Microsoft KB Archive/268515

{|
 * width="100%"|

PRB: Socket Messages Appear to Be Sent with the Wrong Message ID

 * }

Q268515

-

The information in this article applies to:


 * Microsoft Platform Software Development Kit (SDK)

-

SYMPTOMS
A listening TCP socket is used in a WSAAsyncSelect (sListener, hWnd, WndMsgSListener, FD_ACCEPT | FD_READ | FD_WRITE | FD_CLOSE) call, and later the FD_ACCEPT notification occurs and a connected socket is accepted. Then the connected socket is used in a WSAAsyncSelect (sConnected, hWnd, WndMsgSConnected, FD_READ | FD_WRITE | FD_CLOSE) call. It is possible that the application receives the Windows message WndMsgSListener on the connected socket (sConnected in the message's WPARAM) for FD notifications occuring on the connected socket.

CAUSE
On a socket server, connected sockets inherit the FD notification mask from the listening socket. If the WSAAsyncSelect on the listening socket applies a FD notification mask that includes FD notifcations allowed for a connected socket (for example, FD_READ, FD_WRITE, FD_CLOSE), the first few notification messages may be sent before the application calls WSAAsyncSelect for the connected socket. Thus the old Windows message ID, used by the listening socket, is used to send the message.

RESOLUTION
For the listening sockets, do not specify the FD notifications for the events that can happen with connected sockets. The suggestion is to only use FD_ACCEPT with listening sockets.