WSA-Recv Function

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 );

Parameters

Return Value

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.

Remarks

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.

Buffer Management

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.

Flags

The lpFlags parameter can be used to control the behavior of the receive operation. Common flags include:

See Also