Boost asio udp waitForReadyRead
I am trying to implement a function using boost asio udpSocket, that waits until data is ready to be read, or waits until a timeout expires.
using asyc_read and a async_wait, I can do something similar, but I have to read the data. I would like to do the same without reading the data
This would allow a much easier use of the udpSocket class in many situations, but given the the udpSocket int开发者_开发百科erface, I cannot figure out how to implement such a function, without manually buffering the data, and rewriting a sync_read function
best, Dd
Try calling async_receive
(link) using the option message_peek
(link). That way you can set up a timeout-bound read like you were wanting, but without pulling any data off of the receive buffer.
For more details, read the MSDN description of MSG_PEEK (which is the Windows-specific implementation of message_peek
...you need to scroll down to the bottom of the article). That should give you a good idea of how it works in more detail, though you should consult your system's documentation to be absolutely certain.
精彩评论