还是用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.
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时还是阻塞的,不立即返回。