Search code examples
c++windowssocketswinapiiocp

IO Completion Ports and socket send()


Based on my understanding so far of IOCP, when I create a completion port and associate a socket to it, a notification will be sent to the completion port when a socket is ready to be read.

But how send() is handled, I mean if I want to send data, should I just call send()? what about the completion port, does it get any notification regarding send()?


Solution

  • Based on my understanding so far of IOCP, when I create a completion port and associate a socket to it, a notification will be sent to the completion port when a socket is ready to be read.

    NO! One advantage of the IOCP mechanism is that you can queue up read/write requests, with associated buffers, to the kernel and have a kernel threadpool perform the IO operations in kernel state. It's an I/O COMPLETION port, ie. you are notified upon operation completed.

    If it's a read, you get your buffer, (pointer), back with the data already loaded - you don't have to explicitly read/copy it again.

    If it's a write, the data has already gone and your returned buffer, (pointer). is free to be deleted/reused/repooled/whatever.