?
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
Medium Priority
?
1,014 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
[X]
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
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 17814649
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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