简体   繁体   English

如何在C ++中处理异步套接字接收?

[英]How to handle asynchronous socket receiving in C++?

I'm currently using a thread to handle Connect and Send calls asynchronously. 我目前正在使用一个线程来异步处理Connect和Send调用。 This is all working fine, but now I want to make receiving asynchronous too. 这一切都运行正常,但现在我也希望接收异步。 How should I receive data without pausing the whole queue while waiting for data? 在等待数据时如何在不暂停整个队列的情况下接收数据? The only solution I can think of right now is a second thread. 我现在能想到的唯一解决方案是第二个线程。

Look into non-blocking sockets and polling APIs like select(2) / poll(2) / epoll(4) / kqueue(2) . 查看非阻塞套接字和轮询API,如select(2) / poll(2) / epoll(4) / kqueue(2)

Specifically in C++, look into boost::asio . 特别是在C ++中,请查看boost::asio

Depending on what you're doing, non-blocking I/O with select may be the answer. 根据您正在做的事情, 选择非阻塞I / O可能就是答案。

Take a look at this tutorial . 看一下本教程

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

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