异步提升从stdin读取的asio
Boost asio read from stdin asynchronously
我想用boost asio函数async_read((从标准输入(用c++表示,std::cin(中读取。下面的代码没有编译,由于实例化错误,给了我一个很长的错误消息。有人能回答吗,我如何使用这个函数异步读取stdin?
char buf[64];
boost::asio::async_read(std::cin, boost::asio::buffer(buf),
[](const boost::system::error_code &ec, std::size_t size){});
编辑:我知道这里已经提出了类似的问题。使用boost::asio::async_read和stdin?,然而,我不清楚标记的答案与问题的关系
您必须使用posix::stream_descriptor
例如:
using namespace boost::asio;
io_context ioc;
posix::stream_descriptor input_stream(ioc, STDIN_FILENO);
// assume that you already defined your read_handler ...
async_read(input_stream, buffer(buf), read_handler);
ioc.run();
请注意,您不应该将上述代码与std::cin
混合使用
有关更多信息,请参阅此处。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- Async_read_until限制读取的字节大小(Boost::asio)
- TCP 服务器的异步读取使用 boost::asio 打印客户端套接字发送的数据
- 增强 ASIO 和串行端口异步读取
- boost::asio 不会触发读取处理程序,而 Wireshark 会看到传入的数据
- 异步提升从stdin读取的asio
- 如何使用 boost::asio 的 async_read_some() 读取所有可用数据,而无需等待新数据到达?
- boost::asio-async_read_some示例代码没有读取套接字中的所有数据
- 提升 ASIO transfer_exactly读取 0 字节
- boost::asio::async_read_until 不会读取所有消息
- 如何在async_read_until后使用 asio 缓冲区进行连续读取
- 使用 boost::asio 读取 JSON 流,获取完整字符串
- 提升ASIO写入/读取向量
- 是否可以在使用 Boost::asio 之前从套接字读取后执行async_handshake
- 提升::不满足 ASIO 读取处理程序类型要求
- Boost ASIO async_read 没有从服务器读取数据
- Boost ASIO async_read不是从客户端读取数据
- 如何使用boost.asio读取整个Char类型的数据
- 从boost asio streambuf读取会将字节保持在缓冲区中
- 读取:ASIO中的文件结束.插座为什么要关上