You need to call setsockopt(SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT) after AcceptEx() . The received socket is not completely related to the properties of the listening socket and, as such, will not be in a fully connected state until SO_UPDATE_ACCEPT_CONTEXT is set. Some winsock API functions are affected by this, including getpeername() , getsockname() and shutdown() .
If you use ConnectEx() for an outbound connection, you need to call setsockopt(SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT) after ConnectEx() is complete before you can use shutdown() . This is documented behavior on MSDN. It does not say the same for AcceptEx() and SO_UPDATE_ACCEPT_CONTEXT , but shutdown() has a similar restriction for sockets accepted by AcceptEx() .
Remy Lebeau
source share