SORecv / SORecvFrom

Syntax

#include <cafe.h>
#include <cafe/network.h>

int SORecv(int              fd, 
           void            *buffer, 
           int              len, 
           int              flags,
           );


int SORecvFrom(int              fd,
               void            *buffer,
               int              len,
               int              flags,
               struct sockaddr *from,
               int             *fromlen
              );

Parameters

fd Descriptor of socket from which to receive.
buffer Destination buffer.
len Length of the buffer, in bytes. For UDP sockets, len greater than 1478 will cause SO_EMSGSIZE error.
flags Can be ORed from the following values:
  • MSG_OOB........Request out of band data.
  • MSG_PEEK.......Receive without dequeuing the data.
  • MSG_DONTWAIT...Enable non-blocking operation.
from Source address.
fromlen Initialized to the size of the buffer associated with from; modified with the actual length of the address upon return.

Return Values

int, returns the number of bytes received. Upon an error, returns -1 and errno is set to the correct value. Returns a 0 when the peer has performed an orderly shutdown.

Errors

These are errors generated by the socket layer; additional errors may be generated by the underlying protocol modules. See SOLastError.

SO_ELIBNOTREADY Socket library is not initialized.
SO_ENOMEM Insufficient memory in the stack.
SO_EINVAL Specified argument is invalid.
SO_ENOTCONN The socket is associated with a connection-oriented protocol and has not been connected (see SOConnect and SOAccept ).
SO_ENOTSOCK The argument fd does not refer to a socket.
SO_EWOULDBLOCK The socket is marked non-blocking, and the receive operation would block, or a receive timeout was set, and the timeout expired before data was received.
SO_EMSGSIZE The socket requires that message be received atomically, and len made this impossible. For UDP sockets, len greater than 1478 will cause this error.
SO_EABORTED The operation was aborted. When a socket is closed, operations that are blocked on the socket are aborted.
SO_ENOBUFS Insufficient resources in the stack.
SO_EBUSY Socket resource manager busy processing requests.
SO_EABORTED Indicates the operation was aborted. For example, this error can be returned for calls blocked on a socket after the socket is closed by another thread.
SO_EUNKNOWN Unknown error.
SO_ERANGEINVALID Internal API error, invalid error code.
SO_EAPIERROR Internal API error.
SO_ECONNRESET Connection reset.

Description

The SORecv function is normally used only on a connected socket and is identical to SORecvFrom with a null pointer passed as its from argument.

SORecvFrom can return the address from which the message was sent. For connected datagram sockets, SORecvFrom returns the same address as SOGetPeerName; for stream sockets it does not return the socket address of the sender.

If a RST packet is received on an open connection, SORecv and SORecvFrom return 0.

Do Not Call From

SORecv

Callbacks Do not call this function from any callback function.
Interrupt handler Do not call this function from any interrupt handler.
Exception handler Do not call this function from any exception handler.

SORecvFrom

Callbacks Do not call this function from any callback function.
Interrupt handler Do not call this function from any interrupt handler.
Exception handler Do not call this function from any exception handler.

See Also

SOConnect

Revision History

2012/10/09 Updated Errors section.
2012/08/16 Cleanup pass.
2011/07/11 Merged SORecvFrom, additional detail, added Errors section.
2011/02/21 Initial version.


CONFIDENTIAL