当我在debug的时候,执行到该函数时,程序停止运行!没报任何错误,请问这是怎么回事?

解决方案 »

  1.   

    当我在debug的时候,执行到该函数时,程序停止运行!没报任何错误,请问这是怎么回事?
    ----------------------------
    阻塞了??
      

  2.   


    int CUdpSocket::PostRequestData(int i)
    {
        int     err=0;      // Error code 
        ULONG   ulRevBytes; // Number of bytes received
        ULONG   flags=0;    // Receive flags 
        // We use completion routing, so event field can be utilized for additional parameter 
        m_overlap.hEvent = (HANDLE)(&m_overlapBuf[i]);
        err = WSARecvFrom (m_udp_socket,
                           &m_wsaBuf[i],
                           1,
                           &ulRevBytes,
                           &flags,
                           (PSOCKADDR)&m_fromAddr,
                           &m_fromAddrLen,
                           &m_overlap,
                           RcvCompletion
                          );
        if((err==0) || ((err=WSAGetLastError ())==WSA_IO_PENDING))
        {
            return 0;
        }
        return err;
    }
      

  3.   

    If lpCompletionRoutine is not NULL, the hEvent parameter is ignored and can be used by the application to pass context information to the completion routine. A caller that passes a non-NULLlpCompletionRoutine and later calls WSAGetOverlappedResult for the same overlapped I/O request may not set the fWait parameter for that invocation of WSAGetOverlappedResult to TRUE. In this case the usage of the hEvent parameter is undefined, and attempting to wait on the hEvent parameter would produce unpredictable results.The completion routine follows the same rules as stipulated for Windows file I/O completion routines. The completion routine will not be invoked until the thread is in an alertable wait state such as can occur when the function WSAWaitForMultipleEvents with the fAlertable parameter set to TRUE is invoked.The transport providers allow an application to invoke send and receive operations from within the context of the socket I/O completion routine, and guarantee that, for a given socket, I/O completion routines will not be nested. This permits time-sensitive data transmissions to occur entirely within a preemptive context.
      

  4.   

    m_udp_socket是异步socket吗?
      

  5.   

    你看看socket在初始化时是怎么定义的,因为你用的是重叠I/O模式,所以要设置overlapped属性。如果你用的是socket就没事,但是如果你用的是WSASocket,在最后一个参数那里要设置为WSA_FLAG_OVERLAPPED,这样,它就会把每一个每一个套接字与一个事件关联在一起,设置为非阻塞模式,就算没有数据来了,WSARecvFrom 都会立刻返回。至于是套接字什么时候收到信息或者要进行处理,用的是WSAWaitForMulipleEvents函数下面的就不说了,自己去看看吧。