Buffer size UDP receiver. - Networking

This is a discussion on Buffer size UDP receiver. - Networking ; 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, ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Buffer size UDP receiver.

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

  2. Re: Buffer size UDP receiver.

    On Jun 25, 5:47*am, gNash 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

  3. Re: Buffer size UDP receiver.

    On Jun 25, 6:04*pm, David Schwartz wrote:
    > On Jun 25, 5:47*am, gNash 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




  4. Re: Buffer size UDP receiver.

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

  5. Re: Buffer size UDP receiver.

    gNash 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 to Thread