Completion-based event queues
IOCP stands for input/output completion port. This is a completion-based event queue. This type of queue notifies you when events are completed. An example of this is when data has been read into a buffer.
The following is a basic breakdown of what happens in this type of event queue:
- We create an event queue by calling the syscall
CreateIoCompletionPort
. - We create a buffer and ask the OS to give us a handle to a socket.
- We register an interest in
Read
events on this socket with another syscall, but this time we also pass in the buffer we created in (step 2) , which the data will be read to. - Next, we call
GetQueuedCompletionStatusEx
, which will block until an event has been completed. - Our thread is unblocked and our buffer is now filled with the data we’re interested in.
Figure 3.2 – A simplified view of the IOCP flow