更新时间:2022-11-03 14:29:32
Yes, using the non_blocking()
method to put the socket into Asio non-blocking mode:
template<typename SyncWriteStream,
typename ConstBufferSequence>
std::size_t write_nonblock(
SyncWriteStream & s,
const ConstBufferSequence & buffers)
{
s.non_blocking(true);
boost::system::error_code ec;
auto bytes = s.send(buffers, 0, ec);
if (bytes == 0 && !(ec == boost::asio::error::would_block))
throw boost::system::system_error(ec, "write_nonblock send");
return bytes;
}