Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Linux Networking

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-2008, 12:47 PM
gNash
 
Posts: n/a
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.
Reply With Quote
  #2 (permalink)  
Old 06-25-2008, 01: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
  #3 (permalink)  
Old 06-25-2008, 01:23 PM
gNash
 
Posts: n/a
Re: Buffer size UDP receiver.

On Jun 25, 6:04*pm, David Schwartz <dav...@webmaster.com> wrote:
> 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


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



Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 08:46 PM
Rick Jones
 
Posts: n/a
Re: Buffer size UDP receiver.

gNash <ganeshamutha@gmail.com> wrote:
> 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.?


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...
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 08:48 PM
Rick Jones
 
Posts: n/a
Re: Buffer size UDP receiver.

gNash <ganeshamutha@gmail.com> wrote:
> i am receiving UDP packets from sender which sends (sender's


> 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.


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...
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Linux Networking


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:40 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Loans | Problem Mortgage | Brazilian bikini | Remortgages | Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109