Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Windows sockets: WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0, on an FD_READ event, with no data available to read.

Posted on 2006-10-26
1
993 Views
Last Modified: 2012-06-21
Hi,
I'm writing a simple client - server communication application.  My question here is in regards to the server side.

After the client establishes a connection, it then writes 8 bytes.

The following (server side) code section successfully receives the 8 bytes.  The problem is that future calls to WSAWaitForMultipleEvents seem to all return signalled, even though there is no data to read.  To illustrate, I put a for-next loop around the same WSAWaitForMultipleEvents...recv sequence.  The first iteration through the code successfully reads the 8 bytes, but on the 2nd iteration through, the WSAWaitForMultipleEvents call still returns signalled, even though the FD_READ event should have been cleared by the recv call.  See the output below.
Any thoughts on what the problem is would be greatly appreciated.  This is the only worker thread in the application.  

            int iError=WSAEventSelect(m_Sockets[ClientIndex], m_Events[ClientIndex], FD_READ);
            if (iError) Message6(RED,"WSAEventSelect Failed"); else Message6(GREEN,"WSAEventSelect Successful");

            DWORD dwResult;
            for (int k=1; k<4; k++)
            {
                  Message6(BLACK,"Iteration #%d",k);
                  dwResult = WSAWaitForMultipleEvents(1,&m_Events[ClientIndex],FALSE,500,FALSE);
                  if (dwResult==WSA_WAIT_EVENT_0)
                  {      Message6(BLACK,"First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=%x",FD_READ);

                        int iResult = recv(m_Sockets[ClientIndex], (char*)(&dData), 8, 0);
                        if (iResult == SOCKET_ERROR)
                        {
                              int iErr=WSAGetLastError();
                              if (iErr==WSAEWOULDBLOCK)
                                    Message6(BLACK,"WSAEWOULDBLOCK on receive.");
                              else
                                    DisplayWinSockErrorMessage("recv error: ",iErr);
                        }
                        else
                        {
                              Message6(GREEN,"Just received %d bytes of data. %f",iResult,dData);
                        }
                  }

            }


2006.10.26 14:57:59.90851 WSAEventSelect Successful
2006.10.26 14:57:59.90852 Iteration #1
2006.10.26 14:57:59.91472 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91475 Just received 8 bytes of data.
2006.10.26 14:57:59.91476 Iteration #2
2006.10.26 14:57:59.91477 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91478 WSAEWOULDBLOCK on receive.
2006.10.26 14:57:59.91479 Iteration #3
2006.10.26 14:57:59.91480 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91481 WSAEWOULDBLOCK on receive.
0
Comment
Question by:dcShaver
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17814649
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question