Unix Programming - How come recv() can get more than getsockopt(SO_RCVBUF) size?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2005 > How come recv() can get more than getsockopt(SO_RCVBUF) size?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How come recv() can get more than getsockopt(SO_RCVBUF) size?
sisapinusa@gmail.com

2005-10-25, 5:54 pm

Hello,
I don't have any problem even if nobody can't give me an answer.
This question is just curious, but I really want to know.
Socket... hmmm... mysterious..The more I know, the more I don't know..

I get 87380 from getsockopt(SO_RCVBUF).
So, what I guess is, 87380 is supposed to be the maximum stream size
which I can get with recv() function.

I mean, if I do like this:

char szRecvBuff[204800];
int recvsize = recv(nSockFd, szRecvBuff, sizeof(szRecvBuff), 0);

Here, the maximum recvsize value should be less than 87380, but when I
test, sometimes I get bigger size than 87380, such like, 177768, from
recv() function, recvsize.

I tested with non-blocking socket, and I let the tcp client program
keep sending more than 87380 at once for every 1 sec, and I put
sleep(10) before call recv() function in tcp server program so that
server program can wait util the internal buffer is full.

Here is simple psuedo code for my test.

client.c - keep sending 87380 bytes every 1 second.
for (;;) {
send(87380);
sleep(1);
}

server.c - keep recveing every 10 second.
for(;;) {
sleep(10);
recv(sizeof(szRecvBuff));
}

at recv() function, I was expected to get less than 87380, but if I
just let both client/server program run, as I mentioned, I get more
than 87380 with recv() fucntion.

How is it possible?, getsockopt says the maximum internal buffer size
is 87380, but as you can see, kernel seems to have a buffer size more
than 87380 for socket.
If not, how can I get more than 87380 with recv() function?

And it's same with getsockopt(SO_SNDBUF). I get 16384 for SO_SNDBUF,
but I can send more than 16384 at once with send() function above.

What I miss here? What is the point that I'm missing?
So, what is the "Maximum" size that I can get from recv() function?
What is the "Maximun" size the internal kernel buffer for a socket fd?
I'm even confused whether those two are same question or not.

Please, any comments is appreciated.
Thanks,

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com