The WSA-Recv function retrieves data from a connected socket or from a group of sockets in a group I/O operation.
int WSAAPI WSA-Recv( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd, LPDWORD lpFlags, LPWSAOVERLAPPED lpOverlapped, LPWSACOMPLETION_ROUTINE lpCompletionRoutine );
lpBuffers.
DWORD that receives the total number of bytes received by the function.
DWORD that specifies flag values used to control the reception.
WSAOVERLAPPED structure. This structure is used for asynchronous operations.
If the operation completes without error, WSA-Recv returns zero. If the operation is pending or fails with an error other than WSAEWOULDBLOCK, the return value is SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
Possible error codes include:
WSAENOTCONN: The socket is not connected.WSAECONNRESET: The connection reset by peer.WSAEFAULT: The buffer specified by the buffer parameter is not in the user's address space.WSAEINTR: The blocking Winsock call was canceled due to a callback timer.The WSA-Recv function is used to receive data from a socket. It can be used for both synchronous and asynchronous operations.
For overlapped operations, the lpOverlapped parameter must point to a valid WSAOVERLAPPED structure. If the socket is created with the WSA_FLAG_OVERLAPPED flag, the lpOverlapped parameter must not be NULL.
If lpOverlapped is specified, the lpCompletionRoutine parameter can be NULL. If NULL, the system will use the same mechanism to signal I/O completion as used for other overlapped operations on the socket.
If the lpCompletionRoutine is not NULL, it is assumed to be a pointer to a user-supplied completion routine. This routine is invoked upon completion of the WSA-Recv call.
The lpBuffers parameter points to an array of WSABUF structures. Each WSABUF structure contains a pointer to a buffer and the length of that buffer. The WSA-Recv function will attempt to fill these buffers with received data.
The lpFlags parameter can be used to control the behavior of the receive operation. Common flags include:
MSG_PEEK: Peek at incoming message. Data is copied into the buffer but is not extracted from the input queue.MSG_TRUNC: Indicates that the datagram was truncated because it was too long to fit in the buffer.