用closesocket(Socket),关闭socket,使accept函数出错返回。

解决方案 »

  1.   

    Cancelblockcall这个函数好像是CSocket类里面的,我没有用这个类。
      

  2.   

    想要用API函数把阻塞函数的调用取消,你只能用setsockopt函数将此socket设置为非阻塞。
      

  3.   

    还是用close吧,MSDN中在 CANCELBLOCKINGCALL中说道:If an application cancels a blocking operation on a socket, the only operation that the application can depend on being able to perform on the socket is a call to Close, although other operations may work on some Windows Sockets implementations. 
      

  4.   

    假如一个SOCKET是非阻塞的,是不是调用Accept函数时立即返回???
      

  5.   

    为什么我设置了不阻塞调用但还不立即返回???
             int nBufSize;
    BOOL bValue = TRUE;
    nBufSize = sizeof(BOOL);
    socServer.SetSockOpt(SOL_SOCKET, SO_DONTLINGER,
    (char *)&bValue, nBufSize); // accept client connect
    CBaseTCP socRece;
    CSockAddr socReceAddr;
    if (!socServer.Accept(socRece, socReceAddr)) {
    fileSend.Close();
    AfxMessageBox("Socket socket accept");
    return SEND_FILE_EXIT_CODE;
    }调用accept时还是阻塞的,不立即返回。