ISocket.recv

Receives dst.length bytes from the remote but at most as possible with one attempt.

class ISocket
ssize_t
recv
(
void[] dst
,
int flags
)

Parameters

dst void[]

buffer to receive data in

flags int

the bitwise OR of zero or more of the following flags:

MSG_CMSG_CLOEXEC (recvmsg() only; since Linux 2.6.23) Set the close-on-exec flag for the file descriptor received via a Unix domain file descriptor using the SCM_RIGHTS operation (described in unix(7)). This flag is useful for the same reasons as the O_CLOEXEC flag of open(2).

MSG_DONTWAIT (since Linux 2.2) Enables nonblocking operation; if the operation would block, the call fails with the error EAGAIN or EWOULD‐ BLOCK (this can also be enabled using the O_NONBLOCK flag with the F_SETFL fcntl(2)). MSG_OOB This flag requests receipt of out-of-band data that would not be received in the normal data stream. Some proto‐ cols place expedited data at the head of the normal data queue, and thus this flag cannot be used with such proto‐ cols.

MSG_PEEK This flag causes the receive operation to return data from the beginning of the receive queue without removing that data from the queue. Thus, a subsequent receive call will return the same data.

MSG_TRUNC (since Linux 2.2) For raw (AF_PACKET), Internet datagram (since Linux 2.4.27/2.6.8), and netlink (since Linux 2.6.22) sockets: return the real length of the packet or datagram, even when it was longer than the passed buffer. Not imple‐ mented for Unix domain (unix(7)) sockets.

For use with Internet stream sockets, see tcp(7).

MSG_WAITALL (since Linux 2.2) This flag requests that the operation block until the full request is satisfied. However, the call may still return less data than requested if a signal is caught, an error or disconnect occurs, or the next data to be received is of a different type than that returned. MSG_EOR indicates end-of-record; the data returned completed a record (generally used with sockets of type SOCK_SEQ‐ PACKET).

MSG_TRUNC indicates that the trailing portion of a datagram was discarded because the datagram was larger than the buffer supplied.

MSG_CTRUNC indicates that some control data were discarded due to lack of space in the buffer for ancillary data.

MSG_OOB is returned to indicate that expedited or out-of-band data were received.

MSG_ERRQUEUE indicates that no data was received but an extended error from the socket error queue.

Return Value

Type: ssize_t

the number of bytes received on success or -1 on failure. On failure errno is set appropriately.

Errors:

EAGAIN or EWOULDBLOCK The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the time‐ out expired before data was received. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities.

EBADF The argument sockfd is an invalid descriptor.

ECONNREFUSED A remote host refused to allow the network connection (typi‐ cally because it is not running the requested service).

EFAULT The receive buffer pointer(s) point outside the process's address space.

EINTR The receive was interrupted by delivery of a signal before any data were available; see signal(7).

EINVAL Invalid argument passed.

ENOMEM Could not allocate memory for recvmsg().

ENOTCONN The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).

ENOTSOCK The argument sockfd does not refer to a socket.

Meta