开发者

How to handle asynchronous socket receiving in C++?

开发者 https://www.devze.com 2023-01-02 20:46 出处:网络
I\'m currently using a thread to handle Connect and Send calls asynchronously. This is all working fine, but now I want to make receiving asynchronous too. How should I receive data without pausing th

I'm currently using a thread to handle Connect and Send calls asynchronously. This is all working fine, but now I want to make receiving asynchronous too. How should I receive data without pausing the whole queue whil开发者_如何转开发e 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).

Specifically in C++, look into boost::asio.


Depending on what you're doing, non-blocking I/O with select may be the answer.

Take a look at this tutorial.

0

精彩评论

暂无评论...
验证码 换一张
取 消