我正在尝试使用 boost asio udpSocket 实现一个函数,该函数等待数据准备好读取,或者等待超时到期。
使用 asyc_read 和 async_wait,我可以做类似的事情,但我必须读取数据。我想在不读取数据的情况下执行相同的操作,
这将允许在许多情况下更轻松地使用 udpSocket 类,但考虑到 udpSocket 接口,我无法想象出如何实现这样的功能,不用手动缓冲数据,
最好重写一个sync_read函数,dd
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 interface, I cannot figure out how to implement such a function, without manually buffering the data, and rewriting a sync_read function
best, Dd
发布评论
评论(1)
尝试调用
async_receive
(链接)使用选项message_peek
(链接)。这样您就可以像您想要的那样设置超时限制读取,但无需从接收缓冲区中提取任何数据。有关更多详细信息,请阅读MSG_PEEK 的 MSDN 说明 (这是
message_peek
的 Windows 特定实现...您需要向下滚动到文章底部)。这应该能让您更好地了解它是如何工作的,但您应该查阅系统文档才能绝对确定。Try calling
async_receive
(link) using the optionmessage_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.