[英]Concurrent read and async_read_some in boost asio
Assume that an async_read_some service has been enabled on a socket in boost::asio, what will happen if a blocking read on the same socket is called? 假设在boost :: asio中的套接字上启用了async_read_some服务,如果在同一个套接字上调用阻塞读取会发生什么?
A piece of pseudo code looks like: 一段伪代码看起来像:
using boost::asio::local::stream_protocol;
boost::asio::io_service io;
stream_protocol::socket s(io);
s.connect(stream_protocol::endpoint(address));
s.async_read_some(aBuffer, aCallback); // start async_read
boost::thread thread(boost::bind(&boost::asio::io_service::run, &io));
usleep(1000000); // do some stuff
boost::asio::read(bBuffer); // request a blocking read
My naive test shows that the blocking read always get priority : data will first fill the bBuffer before the async callback being called. 我的天真测试显示阻塞读取始终优先 :数据将在调用异步回调之前首先填充bBuffer。 It's a desired behaviour on my side. 这是我所希望的行为。
Question: It is a guaranteed behaviour? 问题:这是一种保证行为吗? On all socket types? 在所有套接字类型?
Boost.Asio does not make this guarantee on any I/O object. Boost.Asio不对任何I / O对象进行此保证。 When a synchronous operation is initiated on an I/O object that has an outstanding asynchronous operation of the same type, the order in which the underlying system calls occur is unspecified. 当对具有相同类型的未完成异步操作的I / O对象启动同步操作时,未指定基础系统调用发生的顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.