PRB: WSAAsyncSelect() Notifications Stop Coming

Last reviewed: November 2, 1995
Article ID: Q94088
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5, 3.51, and 4.0

SYMPTOMS

I have set a WSAAsyncSelect() call to notify me of read (FD_READ) and disconnection (FD_CLOSE). When a read call is posted on my message queue, I continually read from the socket until there are no more characters waiting. After each read, I use a select() call to determine if more data needs to be read. However, after a while, the notifications stop coming. Why is this?

CAUSE

The message queue must be cleared of extraneous notification messages for each read notification message.

RESOLUTION

Call WSAAsyncSelect( sockt, hWnd, 0, 0) to clear the message queue for each read notification.

MORE INFORMATION

Sample Code

WSA_READCLOSE:

  if (WSAGETSELECTEVENT( lParam ) == FD_READ) {

    FD_ZERO( &readfds );
    FD_SET( sockt, &readfds);

    timeout.tv_sec = 0;
    timeout.tv_usec = 0;

    /* Clear the queue of any extraneous notification messages. */

    WSAAsyncSelect( sockt, hWnd, 0, 0);

    while (select(0, &readfds, NULL, NULL, &timeout) != 0) {
      recv(sockt, &ch, 1, 0);
      }

    /* Reset the message notification. */

    WSAAsyncSelect( sockt, hWnd, WSA_READCLOSE, FD_READ | FD_CLOSE);
    }


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbnetwork kbprb
KBSubcategory: NtwkWinsock


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.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.