
WSASend()的返回值
若无错误发生且发送操作立即完成,则WSASend()函数返回0。这时,完成例程(Completion Routine)应该已经被调度,一旦调用线程处于alertable状态时就会调用它。否则,返回SOCKET_ERROR 。通过WSAGetLastError获得详细的错误代码。WSA_IO_PENDING 这个错误码(其实表示没有错误)表示重叠操作已经提交成功(就是异步IO的意思了),稍后会提示完成(这个完成可不一定是发送成功,没准出问题也不一定)。其他的错误代码都代表重叠操作没有正确开始,也不会有完成标志出现。 Error code Meaning WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set. WSAECONNABORTED The virtual circuit was terminated due to a time-out or other failure. WSAECONNRESET For a stream socket, the virtual circuit was reset by the remote side. The application should close the socket as it is no longer useable. For a UDP datagram socket, this error would indicate that a previous send operation resulted in an ICMP Port Unreachable message. WSAEFAULT ThelpBuffers,lpNumberOfBytesSent,lpOverlapped,lpCompletionRoutineparameter is not totally contained in a valid part of the user address space. WSAEINTR A blocking Windows Socket 1.1 call was canceled throughWSACancelBlockingCall. WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. WSAEINVAL The socket has not been bound withbindor the socket is not created with the overlapped flag. WSAEMSGSIZE The socket is message oriented, and the message is larger than the maximum supported by the underlying transport. WSAENETDOWN The network subsystem has failed. WSAENETRESET For a stream socket, the connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. For a datagram socket, this error indicates that the time to live has expired. WSAENOBUFS The Windows Sockets provider reports a buffer deadlock. WSAENOTCONN The socket is not connected. WSAENOTSOCK The descriptor is not a socket. WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, MSG_PARTIAL is not supported, or the socket is unidirectional and supports only receive operations. WSAESHUTDOWN The socket has been shut down; it is not possible toWSASendon a socket aftershutdownhas been invoked with how set to SD_SEND or SD_BOTH. WSAEWOULDBLOCK Windows NT:Overlapped sockets: There are too many outstanding overlapped I/O requests. Nonoverlapped sockets: The socket is marked as nonblocking and the send operation cannot be completed immediately. WSANOTINITIALISED A successfulWSAStartupcall must occur before using this function. WSA_IO_PENDING An overlapped operation was successfully initiated and completion will be indicated at a later time. WSA_OPERATION_ABORTED The overlapped operation has been canceled due to the closure of the socket, the execution of the SIO_FLUSH command inWSAIoctl, or the thread that initiated the overlapped request exited before the operation completed. For more information, see the Remarks section.