(zz)WSAEWOULDBLOCK 與 FD_WRITE 說明

exocet發表於2008-09-09

WinSock Tips

1. WSAEWOULDBLOCK 錯誤說明

在非鎖定套接字上

函式名 說明
WSAAccept, accept 應用程式沒有收到連線請求,再次呼叫,便可檢查連線情況
closesocket 大多數情況下,這個錯誤意味著已隨SO_LINGER選項一道呼叫了
setsockopt,而且已設定了一個非零的超時值
WSAConnect, connect應用程式已初始化,再次呼叫,便可檢查是否完成
WSARecv,recv
WSARecvFrom, recvfrom
沒有收到資料,銷後再次檢查
WSASend, send
WSASendTo, sendto
外出資料無緩衝區可用,銷後再試


2. FD_WRITE 觸發條件

只有在三種條件下,才會發出 FD_WRITE 通知
. connect, WSAConnect ,一個套接字首次建立了連線
. accept, WSAAccept, 套接字被接受以後
. send, WSASend, sendto, WSASendTo操作失敗,返回了 WSAEWOULDBLOCK 錯誤,而且緩衝
再次變得可用時

[@more@]If no incoming data is available at the socket, the recv call blocks and waits for data to arrive according to the blocking rules defined for WSARecv with the MSG_PARTIAL flag not set unless the socket is nonblocking. In this case, a value of SOCKET_ERROR is returned with the error code set to WSAEWOULDBLOCK. The select, WSAAsyncSelect, or WSAEventSelect functions can be used to determine when more data arrives.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/38085/viewspace-1010432/,如需轉載,請註明出處,否則將追究法律責任。