recv() system call


recv(2)                                                               recv(2)



NAME
  recv - Receives messages from connected sockets

SYNOPSIS

  #include <sys/types.h>
  #include <sys/socket.h>

  int recv (
          int socket,
          char *buffer,
          int length,
          int flags );

PARAMETERS

  socket    Specifies the socket descriptor.

  buffer    Points to an address where the message should be placed.

  length    Specifies the size of the address pointed to by the buffer param-
            eter.

  flags     Points to a value controlling the message reception.  The flags
            parameter is formed by logically ORing one or more of the follow-
            ing values, defined in the sys/socket.h file:

            MSG_PEEK  Peek at incoming message.  The data is treated as
                      unread and the next recv() function (or similar func-
                      tion) will still return this data.

            MSG_OOB   Process out-of-band data.

DESCRIPTION

  The recv() function receives messages from a connected socket.  The
  recvfrom() and recvmsg() functions receive messages from both connected and
  unconnected sockets; however, they are usually used for unconnected sockets
  only.

  The recv() function returns the length of the message.  If a message is too
  long to fit in the supplied buffer, excess bytes may be truncated depending
  on the type of socket that issued the message.

  If no messages are available at the socket, the recv() function waits for a
  message to arrive, unless the socket is nonblocking.  If a socket is non-
  blocking, errno is set to [EWOULDBLOCK].

  Use the select() function to determine when more data arrives.

NOTES
  The recv() function is identical to the recvfrom() function with a zero-
  valued address_len parameter, and to the read() function if no flags are
  used.  For that reason, the recv() function is disabled when 4.4BSD
  behavior is enabled (that is, when the _SOCKADDR_LEN compile-time option is
  defined).




RETURN VALUES

  Upon successful completion, the recv() function returns the length of the
  message in bytes.  Otherwise, a value of -1 is returned, and errno is set
  to indicate the error.

ERRORS

  If the recv() function fails, errno may be set to one of the following
  values:

  [EBADF]   The socket parameter is not valid.

  [ENOTSOCK]
            The socket parameter refers to a file, not a socket.

  [EWOULDBLOCK]
            The socket is marked nonblocking, and no data is waiting to be
            received.

  [EINTR]   A signal interrupted the recv() function before any data was
            available.

  [EFAULT]  The data was directed to be received into a nonexistent or pro-
            tected part of the process address space.  The buffer parameter
            is invalid.

RELATED INFORMATION

  Functions: recvfrom(2), recvmsg(2), send(2), sendmsg(2), sendto(2),
  select(2), shutdown(2), socket(2), read(2), write(2) delim off