This function is used to read incoming data on connection-oriented sockets or connectionless sockets. When using a connection-oriented protocol, the sockets must be connected before calling this function. When using a connectionless protocol, the sockets must be bound before calling this function.
The local address of the socket must be known. For server applications, use an explicit bind (Windows Sockets) function or an implicit accept (Windows Sockets) or WSAAccept function. Explicit binding is discouraged for client applications. For client applications, the socket can become bound implicitly to a local address using connect (Windows Sockets), WSAConnect, sendto, or WSASendTo.
For connected or connectionless sockets, the recv function restricts the addresses from which received messages are accepted. The function only returns messages from the remote address specified in the connection. Messages from other addresses are (silently) discarded.
For connection-oriented sockets (type SOCK_STREAM, for example), calling recv will return as much information as is currently available — up to the size of the buffer supplied. For connectionless sockets (type SOCK_DGRAM or other message-oriented sockets), data is extracted from the first enqueued datagram (message) from the destination address specified by the connect function.
If the datagram or message is larger than the buffer supplied, the buffer is filled with the first part of the datagram and recv generates the error WSAEMSGSIZE. For unreliable protocols (for example, UDP), the excess data is lost; for reliable protocols, the data is retained by the service provider until it is successfully read by calling recv with a large enough buffer.
If no incoming data is available at the socket, the recv function 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 or WSAEventSelect functions can be used to determine when more data arrives.
If the socket is connection-oriented, the remote side has shut down the connection gracefully, and all data has been received, a recv function will complete immediately with zero bytes received. If the connection has been reset, a recv function will fail with the error WSAECONNRESET.
The flags parameter can be used to influence the behavior of the recv function invocation beyond the options specified for the associated socket. The following table shows flags in the default service provider that Windows Embedded CE does not support (although other providers might support them).
| Value | Description |
| MSG_PEEK | Peeks at the incoming data. The data is copied into the buffer but is not removed from the input queue. The function then returns the number of bytes currently pending to receive. |
| MSG_OOB | Processes OOB data. |
If a client application is run on a computer with a TCP/IP implementation that does not set the push bit on send operations, response delays may result. It is best to correct this on the client; however, IgnorePushBitOnReceives, was added to Afd.sys in Microsoft® Windows NT® 4.0 and Microsoft® Windows® 2000 to force it to treat all arriving packets as though the push bit were set. Windows Embedded CE does not support IgnorePushBitOnReceives.
For more inforamtion about IrDA support in Windows Embedded CE, see Infrared Communications.