View Single Post
  #2 (permalink)  
Old 06-25-2008, 02:04 PM
David Schwartz
 
Posts: n/a
Re: Buffer size UDP receiver.

On Jun 25, 5:47*am, gNash <ganeshamu...@gmail.com> wrote:
> Hi.
>
> * * * *I have little confusion on setsockopt. I am kindly requesting
> every one for clear me on it..
>
> * * * I used system call to increase the receiver buffer size by,
>
> * * *int socketbuff =10240; //10K
> * * *int sizesock * = sizeof(socketbuff);
>
> * * *setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &socketbuff, sizesock);
>
> * * *but when i used the system call to know receiver buffer size
>
> * * *getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &socketbuff,
> &sizesock);
>
> * * * but it given the socketbuff is 20K ie 20480 .
>
> * * * I donot know why i am getting twice then what is set. *What
> basic thing i am missing here. * Please kindly help me to know what
> and why this happening exactly.?


When you set the socket buffer, you are setting the number of data
bytes you want it to hold. Your OS has decided that the best way to
make a socket buffer hold 10,240 data bytes is to crate a 20,480 byte
socket buffer. This is so because the socket buffer doesn't just hold
data bytes, it also holds addressing information so you can use
'recvmsg'.

When you set the receive buffer, you are setting the number of
application data bytes you would like it to be sized for. When you get
the receive buffer, you are getting the actual number of bytes
allocated for the buffer.

2x is a fudge factor.

DS
Reply With Quote