简体   繁体   English

c ++ boost:asio将socket转换为流?

[英]c++ boost:asio convert socket to stream?

I am using boost::asio in both async and sync way. 我在异步和同步方式中使用boost::asio One thread in my application async_accept a socket, and the other thread read/write from that socket synchronously. 我的应用程序中的一个线程async_accept一个套接字,另一个线程同步从该套接字读/写。

AFAIK boost::asio::ip::tcp::iostream object can be created by connecting to an endpoint directly. 可以通过直接连接到端点来创建AFAIK boost::asio::ip::tcp::iostream对象。 I am looking for a way to get a stream object from a socket obj, so I can make my communication lib generic. 我正在寻找一种从套接字obj获取流对象的方法,所以我可以使我的通信库通用。 Is there a way to get that object from an socket obj? 有没有办法从套接字obj中获取该对象?

Avoid internally mixing sync with async. 避免内部混合同步与异步。 Externally emulate one of those using other. 外部模仿其中一个使用其他。 Since asio is async use it async and emulate sync by waiting async operation to complete. 由于asio是异步使用异步并通过等待异步操作来完成模拟同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM