简体   繁体   English

Boost Asio UDP白天服务器异步接收

[英]Boost Asio UDP Daytime Server Async receive

I've been learning boost asio recently, especially UDP. 我最近一直在学习boost asio,尤其是UDP。 I am familiar with the basics, but had a question regarding how UDP handles incoming messages. 我熟悉一些基础知识,但是对UDP如何处理传入消息有疑问。 In the tutorial (see source code here: http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/tutorial/tutdaytime6/src.html ), the UDP server operates something like (very pseudo-code): 在本教程中(请参见此处的源代码: http : //www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/tutorial/tutdaytime6/src.html ),UDP服务器的运行方式类似于(非常伪码):

startReceive(){
    async_receive(boost::bind(handler),...other params);
}

handler(){
    doStuffToDataReceived();
    startReceive(); //start the receiving process over again to allow it to receive more data
}

My question is, if data arrives to the server during the time that it is in "doStuffToDataReceived()", before it startReceives over again, does that data get lost, or does it sit there and wait for startReceive to happen again and then is immediately retrieved? 我的问题是,如果数据在“ doStuffToDataReceived()”期间到达服务器,则在startReceive再次接收之前,数据是否丢失了,还是坐在那里等待startReceive再次发生,然后是立即检索?

Thanks! 谢谢!

UDP stack has a buffer, so the data in the above example wouldn't get lost. UDP堆栈具有缓冲区,因此上述示例中的数据不会丢失。

Note however, that UDP is allowed to drop packets under various circumstances. 但是请注意,在各种情况下都允许UDP丢弃数据包。 So, as the throughput of the UDP server grows, the timings of doStuffToDataReceived might become much more critical. 因此,随着UDP服务器吞吐量的增长, doStuffToDataReceived的时序可能变得更加关键。

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

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