Question

I'm trying to work myself through the socket jungle and came across non blocking sockets with overlapped I/O. I have three books at home which only mention this concept but don't really explain it or give me any examples.

So what I'm looking for is an article where this get's explained with an example or just an example I can work myself through. It would be good if this would be for windows but I guess I should be able to transfer it from unix as well.

I don't mind a book as source but I would be glad to avoid another 50$. So far I only found the very basic concept and basic comparisons with other socket models. It's not that I don't understand their concept but I would like to see them in action and maybe get a good explanation of how they work. ( I don't mind long articles at all :) )

Was it helpful?

Solution

The phrase 'non-blocking sockets' usually refers to use of the FIONBIO socket option, which makes a call to read() return immediately even if there is no data ready to read. (It returns with an EWOULDBLOCK error.)

Overlapped I/O is something specific to the Windows API (and not available on UNIX for example). The FIONBIO socket option is not used, neither are the traditional Berkeley socket API function calls (read() etc).

(For a POSIX equivalent on Linux, refer to 'man aio' or type man aio into your favourite search engine.)

Now that you understand that 'non-blocking sockets' and 'overlapped I/O' are two different approaches (and not to be mixed), finding helpful articles on each should be much easier.

The MSDN documentation on overlapped I/O is actually very good. If you are doing Windows programming then you really need to be using overlapped I/O for anything where performance and scalability matters. Here's a good starting point:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365603%28v=vs.85%29.aspx

(This MSDN article is about pipes, but it is exactly the same using sockets.)

Also, be aware that WaitForMultipleObjects() doesn't scale as well as using I/O completion ports, but get comfortable with the former first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top