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.
+1
A:
Look into non-blocking sockets and polling APIs like select(2)
/poll(2)
/epoll(4)
/kqueue(2)
.
Specifically in C++, look into boost::asio
.
Nikolai N Fetissov
2010-06-10 18:21:50
Non-blocking sockets should be enough if you handle the case that recv() does not read any data (which is easy). Using select() or something similar has its advantages but also drawbacks. It's up to you to decide what suits your needs better.
PeterK
2010-06-11 16:03:40
A:
Depending on what you're doing, non-blocking I/O with select may be the answer.
Robert S. Barnes
2010-06-11 15:59:12