DOCUMENT:Q129974 06-NOV-1999 [win16sdk] TITLE :BUG: Winsock--Lost FD_WRITE Notifications PRODUCT :Microsoft Windows Software Development Kit PROD/VER:WINDOWS:3.1 OPER/SYS: KEYWORDS:kbnetwork kbAPI kbSDKPlatform kbOSWin310bug kbWinsock kbGrpDSNet ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Windows Software Development Kit (SDK) 3.1 ------------------------------------------------------------------------------- SYMPTOMS ======== In both of the following situations, the initial FD_WRITE notifications are never received: - Create a datagram socket and call WSAAsyncSelect() with interest in FD_WRITE notification. -or- - Create a stream socket, call connect() to connect to a TCP server and call WSAAsyncSelect() with interest in FD_WRITE notification. RESOLUTION ========== In the first case, call the bind() function in addition to the socket() function as shown: SOCKADDR_IN source_sin; source_sin.sin_family = AF_INET; source_sin.sin_addr.s_addr = htonl(INADDR_ANY); source_sin.sin_port = htons(0); s = socket(AF_INET, SOCK_DGRAM, 0); bind(s, (struct sockaddr FAR *)&source_sin,sizeof(source_sin)); WSAAsyncSelect(s, hWnd, WSA_WRITE, FD_WRITE); The window specified by hWnd in WSAAsyncSelect() will now receive the FD_WRITE notifications properly. In second case, call socket() and call connect() asynchronously as shown: SOCKADDR_IN dest_sin; dest_sin.sin_family = AF_INET; dest_sin.sin_addr.s_addr = htonl(SERV_HOST_ADDR); dest_sin.sin_port = htons(SERVER_TCP_PORT); s = socket(AF_INET, SOCK_STREAM, 0); WSAAsyncSelect(s, hWnd, WSA_WRITE, FD_CONNECT | FD_WRITE); connect(s, (struct sockaddr FAR *)&dest_sin, sizeof(dest_sin); STATUS ====== Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available. MORE INFORMATION ================ If a datagram client is not expecting to receive a response from a server, it can send data without first binding the datagram socket to a specific port. According to this behavior, a datagram socket should be able to receive FD_WRITE notifications after calling socket() and WSAAsyncSelect(). Additional query words: ====================================================================== Keywords : kbnetwork kbAPI kbSDKPlatform kbOSWin310bug kbWinsock kbGrpDSNet Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK310 Version : WINDOWS:3.1 Issue type : kbbug ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1999.