提升Asio Peek和完成条件 [英] Boost Asio Peek and Completion Condition
问题描述
我正在使用Boost Asio建立套接字连接.我想在不使用缓冲区的情况下偷看缓冲区中的数据,并且我想使用完成条件来确保必要时可以停止阻塞调用.
I am using Boost Asio to set up a socket connection. I would like to peek at the data in the buffer without consuming it, and I would like to use a completion condition to ensure that I could stop the blocking call if necessary.
我可以从可能的message_flags之一是 basic_stream_socket :: message_peek .但是,此调用将阻塞,直到读取至少一个字节或发生错误为止.我可以从阅读:
One of the possible message_flags is basic_stream_socket::message_peek. However, this call blocks until at least one byte is read or an error occurs. I can get the completion condition functionality from read:
template<
typename SyncReadStream,
typename MutableBufferSequence,
typename CompletionCondition>
std::size_t read(
SyncReadStream & s,
const MutableBufferSequence & buffers,
CompletionCondition completion_condition,
boost::system::error_code & ec);
我可以提供一个completion_condition方法,该方法在继续之前检查是否应中止该呼叫.
I can provide a completion_condition method which checks if the call should be aborted before continuing.
我的问题是:是否可以在同一方法调用中获取message_flags参数和completement_condition参数?
My question is this: Is there a way to get a message_flags parameter and a completion_condition parameter in the same method call?
推荐答案
我想在不使用缓冲区的情况下偷看缓冲区中的数据, 我想使用一个完成条件来确保我可以 如有必要,停止阻止通话.
I would like to peek at the data in the buffer without consuming it, and I would like to use a completion condition to ensure that I could stop the blocking call if necessary.
不要这样做.使用异步方法,例如async_read()
和async_write()
.要停止未完成的异步操作,请使用
Don't do this. Use asynchronous methods such as async_read()
and async_write()
. To stop outstanding asynchronous operations, use cancel()
.
这篇关于提升Asio Peek和完成条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!