Search code examples
c++windowssocketsnetwork-programmingoverlapped-io

How does Overlapped I/O relates to the concept of blocking and non-blocking sockets?


I am wondering does using Overlapped I/O means that I am using the socket in a non-blocking mode, or does the concept of blocking and non-blocking sockets is not related to the concept of Overlapped I/O.


Solution

  • I would say they are not related to one another. Blocking vs. Non-Blocking for sockets is straight forward. If you're calling send() or recv() in non-blocking mode and the socket doesn't have anything available (no outbound buffer space for send(), no inbound data for recv()), you receive an error response of WSAWOULDBLOCK. If in blocking mode, the function will simply not return until the requested operation has completed or an error has occurred.

    However, I/O overlapping is more of a delegate pattern. It will accept your WSASend() or WSARecv() request and handle it for you. However, this isn't going to be as soon as the function returns. Instead these functions receive a pointer to a callback that the client specifies. Once the send/recv operation is completed, you are notified via the callback method you provided.

    I would say I/O Overlapping is to remove the need for client programmers to continuously check non-blocking sockets and calling select() to poll them.