Using winsock, you can configure sockets or seperate I/O operations to "overlap". This means that calls to perform I/O are returned immediately, while the actual operations are completed asynchronously by separate worker threads.
Winsock also provides "completion ports". From what I understand, a completion port acts as a multiplexer of handles (sockets). A handle can be demultiplexed if it isn't in the middle of an I/O operation, i.e. if all its I/O operations are completed.
So, on to my question... does linux support completion ports or even asynchronous I/O for sockets?
Use boost::asio. Hands down. It has a mild learning curve, but it's cross-platform, and automatically uses the best available method for the system you're compiling on. There's simply no reason not to.
I know that this isn't quite an answer to your question, but it's the best advice I could give.
I don't fully understand what you mean by "completion ports". All I can say is that you can use sockets in non-blocking mode, which means that calls return immediately.
This reference is quite old but is comprehensive in a sense that it covers
select()
etc.: http://rhoden.id.au/doc/sockets2.htmlAnd here is the GNU manual on sockets: http://www.gnu.org/software/libc/manual/html_node/Sockets.html
If you're looking for something exactly like IOCP, you won't find it, because it doesn't exist.
Windows uses a notify on completion model (hence I/O Completion Ports). You start some operation asynchronously, and receive a notification when that operation has completed.
Linux applications (and most other Unix-alikes) generally use a notify on ready model. You receive a notification that the socket can be read from or written to without blocking. Then, you do the I/O operation, which will not block.
With this model, you don't need asynchronous I/O. The data is immediately copied into / out of the socket buffer.
The programming model for this is kind of tricky, which is why there are abstraction libraries like libevent. It provides a simpler programming model, and abstracts away the implementation differences between the supported operating systems.
There is a notify on ready model in Windows as well (select or WSAWaitForMultipleEvents), which you may have looked at before. It can't scale to large numbers of sockets, so it's not suitable for high-performance network applications.
Don't let that put you off - Windows and Linux are completely different operating systems. Something that doesn't scale well on one system may work very well on the other. This approach actually works very well on Linux, with performance comparable to IOCP on Windows.
IOCP is pronounced "asynchronous I/O" on various UNIX platforms:
Boost ASIO implements Windows style IOCP (Proactor design pattern) on Linux using epoll (Reactor pattern). See http://think-async.com/Asio/asio-1.5.3/doc/asio/overview/core/async.html
Linux kernel does provide the "I/O block completion" concept, everytime you use the "blk_complete_request" API for example. Another example:
http://lxr.free-electrons.com/source/kernel/sched/completion.c
And as explained here:
http://www.ibm.com/developerworks/library/l-async/
linux does have both synchronous and asynchronous I/O block completion API.
The above are all at the kernel level. At the userspace level there is the "io_submit()" API:
http://www.fsl.cs.sunysb.edu/~vass/linux-aio.txt
which detailed the complete set of io_*() APIs.
Partially similar question:
Is there really no asynchronous block I/O on Linux?