如何处理异步套接字接收C ++? [英] How to handle asynchronous socket receiving in C++?

查看:119
本文介绍了如何处理异步套接字接收C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用一个线程来处理连接和发送异步调用。这是所有工作正常,但现在我想使异步接收过。我应该如何获得无需暂停整个队列在等待数据的数据?我现在能想到的唯一的解决办法是第二个线程。

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 while waiting for data? The only solution I can think of right now is a second thread.

推荐答案

。看看非阻塞套接字和轮询API,如 选择(2) /的 调查(2) /的 的epoll(4) /的 的kqueue(2)

Look into non-blocking sockets and polling APIs like select(2)/poll(2)/epoll(4)/kqueue(2).

具体到C ++,看看<一个href=\"http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio.html\"><$c$c>boost::asio.

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

这篇关于如何处理异步套接字接收C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆