Socket Error: WSAGetOverlappedResult fails sometimes 
Author Message
 Socket Error: WSAGetOverlappedResult fails sometimes

I have two MFC programs communicating over multiple sockets.  At
present,during development, both programs are running on the same NT
machine.  I am using Winsock2, with the overlapped I/0 model.
 The programs start out by exchanging a fixed set of messages.
Sometimes the communication fails at a particular point, and sometimes
it works.  I haven't been able to figure out a pattern.
 The error occurs in the client, which is waiting for an
acknowledgement of a command that it sent to the server. The client is
running WSAWaitForMultipleEvents in a thread. When the event is
signaled, the thread posts a message to the main thread. The main
thread runs WSAGetOverlappedResult, which, when the error occurs,
returns FALSE. The error returned by WSAGetLastError() is 995. 995 is
a system error code called ERROR_OPERATION_ABORTED, "The I/O operation
has been aborted because of either a thread exit or an application
request. "  I can't figure out how to apply this message to my
situation.
  The server is not reporting any errors.
  Thanks very much !
        Elaine

  Here are some fragments of the code:

  // The following code runs in a thread on the client

    while (TRUE)
     {
       if ((Index = WSAWaitForMultipleEvents(MAXCONNECTIONS,
                        ptp->EventArray,FALSE,WSA_INFINITE,FALSE))
                        == WSA_WAIT_FAILED)
                {
                   // handle error
                }              

                Index -= WSA_WAIT_EVENT_0;

                WSAResetEvent(ptp->EventArray[Index])

        // post a message to the main thread, so that the main thread
handles the
        // socket event
        while (::PostMessage(ptp->hWnd,SOCKET_THREADMESSAGE,
                (WPARAM) Index,(LPARAM)0) != TRUE)
                        {
                        }
        }

  // Code in the main thread. This is the call that fails.

                DWORD BytesTransferred=0;
                DWORD Flags;
                BOOL retval=TRUE;
                WSASetLastError(0);
                if ((retval=WSAGetOverlappedResult(m_Socket,&m_Overlapped,&BytesTransferred,
                        FALSE,&Flags))== FALSE || BytesTransferred == 0)
                {
                        sprintf(m_errMsg," error %d",
                                WSAGetLastError());
                }



Sat, 20 Mar 2004 03:11:34 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. puzzled socket question: send function sometimes works well,sometimes works failed???

2. puzzled socket question: send function sometimes works well,sometimes works failed???

3. puzzled socket question: send function sometimes works well,sometimes works failed???

4. DCOM Proxy stub DLL fails to register - SOMETIMES ...

5. SetCooperativeLevel fails SOMETIMES...why?

6. CreateProcess() sometimes fails to start QuickWin application

7. debug version works, release version sometimes fails

8. ICON fails to load sometimes

9. RpcNsBindingLookupBegin SOMETIMES fails

10. LoadFrame sometimes fails on NT, then requires reboot to fix

11. RegQueryValueEx failing sometimes.

12. GetMethod() sometimes fails in recursive call

 

 
Powered by phpBB® Forum Software