Buffer size UDP receiver.
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.?
Thanks in advance,
Ganesh.
Re: Buffer size UDP receiver.
On Jun 25, 5:47*am, gNash <ganeshamu...@gmail.com> wrote:[color=blue]
> 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.?[/color]
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
Re: Buffer size UDP receiver.
On Jun 25, 6:04*pm, David Schwartz <dav...@webmaster.com> wrote:[color=blue]
> On Jun 25, 5:47*am, gNash <ganeshamu...@gmail.com> wrote:
>
>
>[color=green]
> > Hi.[/color]
>[color=green]
> > * * * *I have little confusion on setsockopt. I am kindly requesting
> > every one for clear me on it..[/color]
>[color=green]
> > * * * I used system call to increase the receiver buffer size by,[/color]
>[color=green]
> > * * *int socketbuff =10240; //10K
> > * * *int sizesock * = sizeof(socketbuff);[/color]
>[color=green]
> > * * *setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &socketbuff, sizesock);[/color]
>[color=green]
> > * * *but when i used the system call to know receiver buffer size[/color]
>[color=green]
> > * * *getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &socketbuff,
> > &sizesock);[/color]
>[color=green]
> > * * * but it given the socketbuff is 20K ie 20480 .[/color]
>[color=green]
> > * * * 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.?[/color]
>
> 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[/color]
Thank you very much. I understand what exactly happened.
And i have one more interesting issue for me. Please help me
to clear.
i am receiving UDP packets from sender which sends (sender's
buffer size is 4K)..
receiver (Kernel receiver socket size 100K , receiver buffer
size is 20K).
while receiving i used water mark level value upto 10K , and i
am using MSG_WAITALL in recvfrom system call. but recvfrom returning
4K ever.
I cannot understand what is the problem is and why it is not
waited for fill completely.
Please help me again find why it is not happening and how to that
block till fil.
Thanks in Advance,
Ganesh
Re: Buffer size UDP receiver.
gNash <ganeshamutha@gmail.com> wrote:[color=blue]
> 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.?[/color]
Linux behaves that way - some of the extra space is for "overhead" and
whatnot. You will find that as you start asking for larger and larger
sizes you will get to a point where what you get is not 2X what you
request - you will have hit one of the sysctl limits on the system on
which you are running.
rick jones
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
Re: Buffer size UDP receiver.
gNash <ganeshamutha@gmail.com> wrote:[color=blue]
> i am receiving UDP packets from sender which sends (sender's[/color]
[color=blue]
> while receiving i used water mark level value upto 10K , and i
> am using MSG_WAITALL in recvfrom system call. but recvfrom returning
> 4K ever.[/color]
[color=blue]
> I cannot understand what is the problem is and why it is not
> waited for fill completely.[/color]
I could easily be mistaken, but I don't think that MSG_WAITALL is
supposed to have any effect on a UDP socket (might be more accurate to
say SOCK_DGRAM socket, not sure). You get one datagram's worth of
data per receive call. Any further aggregation of the data in
multiple UDP datagrams is up to the application.
rick jones
--
firebug n, the idiot who tosses a lit cigarette out his car window
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...