简体   繁体   English

OS是否缓冲UDP的数据包

[英]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? os是否会缓冲数据包并等待套接字再次监听,或者数据包是否丢弃?

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

Note: The application is running on Linux(Ubuntu 12.04) 注意:应用程序在Linux上运行(Ubuntu 12.04)

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. 您可以使用带有SO_RCVBUF选项的getsockopt()来查看/更改接收缓冲区大小,以及发送缓冲区的SO_SNDBUF 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. 默认值通常介于32K到256K之间,它将为您缓冲。

数据包将被放入队列中,并在收到当前数据包后进行检索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM