I believe your actual question is probably "Can I tell how much data isQuote:>I know that when I writing TCP/IP socket program in C, the system will
>allocate a buffer to hold the data to be sent and received, how can I
>check the size of this buffer?, how can I change the size of this buffer
But as to the question you actually posed...assuming we're talking about
STREAM sockets and not UDP...
When you 'write()' or 'send()' data is "passed" to TCP/IP.
TCP/IP is responsible for delivering this data to the peer.
TCP/IP may break up the data into multiple "transmissions" and
reassemble it on the Peer's side, in the proper sequence.
As to the buffer size, there is a "send" buffer and a "receive" buffer
on each side. Whose size you can determine with getsockopt() &
SO_SNDBUF/SO_RCVBUF...and whose size you can modify with setsockopt().
When you do a write(), if there is sufficient unused room in your buffer
to place your data, then it is copied into the send buffer and control
is passed back to your program. If on the other hand there is
insufficient room in your send buffer then your program is put to sleep
until enough data has been sent to the peer to free up enough space in
your send buffer to copy your data in. At that time control is then
passed back to your program.
I suggest reading W. Richard Stevens "Unix Network Programming" volume I.
Don't program sockets without it!!!
> > I know that when I writing TCP/IP socket program in C, the system will
> > allocate a buffer to hold the data to be sent and received, how can I
> > check the size of this buffer?, how can I change the size of this buffer
> > also?
> See man getsockopt and the options SO_RCVBUF ans SO_SNDBUF.
size_t size_of_buf = sizeof(max_msg_size);
sock = socket(AF_INET, SOCK_STREAM, 0);
rc = getsockopt(sock, SOL_SOCKET, SO_RCVBUF,
I am having performance problems running a Nescape client on a Solaris 2.4
machine with ATM board (SBA-200 by Fore Systems).
I have a server with Solaris 2.3 and ATM board; if the client runs on
SunOS 4.1.3 machine, the performance is good (about 0,5 s. for 1.2 Mbyte
file). If the client runs on Solaris 2.4, the performance is much worse (a
few seconds for the same file).
Apparently the problem is the TCP receive buffer size, that is bigger for
SunOS than for Solaris. Moreover the default size is settable under SunOS,
but I could not find a way to resize it under Solaris (the default is now
8 Kbyte, slightly smaller than the MTU for ATM interfaces).
I temporarily solved the problem using a 1500-byte MTU for the ATM
interface (the time is now about 1 s.), but I am looking for a way to
increase the default TCP receive buffer size to 64 kbyte.
Any idea ?