Mike G
Mike G

Reputation: 4959

Does the OS buffer packets for UDP

For a single threaded server, I have the code below. I am wondering, what would happen if I receive a packet(and start processing it) and another packet arrives, while I am not listening (busy processing). Would the os buffer the packet and waits till the socket is listening again, or is the packet dropped?

            While(true){
                UDPsocket.receive(packetBuff);
                //Do stuff
            }

Note: The application is running on Linux(Ubuntu 12.04)

Upvotes: 1

Views: 519

Answers (2)

whamma
whamma

Reputation: 8338

The operating system has a receive buffer where it can store data when your program is busy. You can use getsockopt() with the SO_RCVBUF option to see/change what the receive buffer size is, and SO_SNDBUF for the send buffer. There is usually a system-wide default, and a system-wide maximum size you can set for this.

What the default is, and how to see that depends on which operating system you're using. The default is usually somewhere between 32K and 256K of data that it will buffer for you.

Upvotes: 2

choz
choz

Reputation: 17898

the packet will be placed in queue and retrieved after you receive the current one.

Upvotes: 1

Related Questions