开发者

Multiple parallel calls to udp::socket::async_receive_from - undefined behaviour?

I am using boost::asio to create a server application, specifically the UDP APIs. Right now I start multiple threads from a pool listening to separate buffers using async_receive_from. This works great on Ubuntu where I develop mostly.

However, when compiling for windows, my callback gets called many times for each sent buffer, with only one reporting that something was found, the others report that zero bytes were sent.

I have lo开发者_如何学JAVAoked at the boost::asio docs, and I know that the write/read free functions must be called serially - but I have been unable to find any information as to whether the same holds for the async_receive_ functions.

Should I simply call async_receive_ once instead?


It holds for all the async_xxx functions, you must never call a function on a given socket till the previous one completes - or you'll end up with rubbish (or undefined behaviour)...

EDIT: I work on linux, and I'm surprised that you see it working correctly, as I definitely don't.

EDIT SOME MORE: do it as shown in the docs, i.e. in the handler for the async_read_some call for example, queue the next read.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜