IOCP中该函数是阻塞的还是非阻塞的

解决方案 »

  1.   

    看你参数中的那个s参数了。
    msdn上说:
    A socket in default mode (blocking) will block until a connection is present when an application calls WSAAccept and no connections are pending on the queue.A socket in nonblocking mode (blocking) fails with the error WSAEWOULDBLOCK when an application calls WSAAccept and no connections are pending on the queue. After WSAAccept succeeds and returns a new socket handle, the accepted socket cannot be used to accept any more connections. The original socket remains open and listens for new connection requests.
      

  2.   

    UINT WINAPI CIOCPServer::ThreadFuncForAccept(void* pParam)
    {
    SThreadParam* pAcceptParam = (SThreadParam*)pParam;
    CIOCPServer*pIOCPServer = pAcceptParam->pIOCPServer;
    SOCKET ListenSocket = pAcceptParam->sSocket;
    HANDLE hCompletionPort = pAcceptParam->hCompletionPort;
    BOOL bExit = FALSE;
    while (!bExit)
    {
    // 处理连接请求
    sockaddr saClient;
    int iClientSize = sizeof(saClient);
    SOCKET AcceptSocket = WSAAccept(ListenSocket, &saClient, &iClientSize, NULL, NULL);
    if ( AcceptSocket == SOCKET_ERROR )
    {
    // 异常错误事件
    pIOCPServer->OnError(INVALID_CLIENT_ID, WSAGetLastError());
    continue;
    }
    以上是原程序,别人的代码,我猜可是是阻塞的,因为没有注册网络事件,谁帮我来肯定一下
      

  3.   

    IOCP不是向windows注册网络事件而后回调。是对windows中io读写的异步操作模式的实现。因此,同样的文件读写也可以用iocp,网络消息也可用writefile和readfile。
    iocp中如果需要使用异步accept,需要用到AcceptEx,这是Mswsock.dll种提供的。其使用方法见msdn
      

  4.   

    ListenSocket
    参数创建的时候是blocking还是nonblocking的,
      

  5.   

    貌似那个华丽的while (!bExit)已经基本上确定了WSAAccept阻塞的身份
      

  6.   


    那个很炫的while(!bExit)里面,WSAAccept不过是为接收的连接做了一个条件检查,还是阻塞的。