


recv(3)                                                   recv(3)


NNAAMMEE
       recv, recvfrom - receive a message from a socket

SSYYNNOOPPSSIISS
       ##iinncclluuddee <<ssyyss//ssoocckkeett..hh>>

       iinntt rreeccvv((iinntt ss,, vvooiidd **bbuuff,, iinntt lleenn,, iinntt ffllaaggss));;


   AAFF__UUNNIIXX oonnllyy::
       ##iinncclluuddee <<ssyyss//uunn..hh>>

       iinntt rreeccvvffrroomm((iinntt ss,, vvooiidd **bbuuff,, ssiizzee__tt lleenn,, iinntt ffllaaggss,,
              ssttrruucctt ssoocckkaaddddrr **ffrroomm,, ssiizzee__tt **ffrroommlleenn));;

DDEESSCCRRIIPPTTIIOONN
       _r_e_c_v  and  _r_e_c_v_f_r_o_m  are  used  to receive messages from a
       socket.

       _s is a socket descriptor from which messages are received.
       _b_u_f is a pointer to the buffer into which the messages are
       placed.  _l_e_n is the maximum number of bytes that  can  fit
       in the buffer referenced by _b_u_f.

       If  the  socket uses connection-based communications, such
       as a SOCK_STREAM socket, these  calls  can  only  be  used
       after  the  connection  has  been  established  (see  _c_o_n_-
       _n_e_c_t(3)).  For connectionless sockets such as  SOCK_DGRAM,
       these  calls  can  be  used  whether a connection has been
       specified or not.

       _r_e_c_v_f_r_o_m operates in the same manner as _r_e_c_v  except  that
       it  is able to return the address of the socket from which
       the message was sent.   For  connected  datagram  sockets,
       _r_e_c_v_f_r_o_m  simply  returns  the  same  address  as _g_e_t_p_e_e_r_-
       _n_a_m_e(2).  For stream sockets, _r_e_c_v_f_r_o_m retrieves  data  in
       the  same  manner  as _r_e_c_v, but does not return the socket
       address of the sender.  If _f_r_o_m is  non-zero,  the  source
       address  of  the  message  is placed in the socket address
       structure pointed to by _f_r_o_m.  _f_r_o_m_l_e_n is  a  value-result
       parameter,  initialized to the size of the structure asso-
       ciated with _f_r_o_m, and modified on return to  indicate  the
       actual  size  of  the address stored there.  If the memory
       pointed to by _f_r_o_m is not  large  enough  to  contain  the
       entire  address,  only  the  first  _f_r_o_m_l_e_n  bytes  of the
       address are returned.

       The length of the message is returned.

       For message-based sockets such as SOCK_DGRAM,  the  entire
       message  must be read in a single operation.  If a message
       is too long to fit in  the  supplied  buffer,  the  excess
       bytes  are  discarded.   For  stream-based sockets such as
       SOCK_STREAM, there is no concept  of  message  boundaries.



                             MiNT-Net                           1





recv(3)                                                   recv(3)


       In  this  case, data is returned to the user as soon as it
       becomes available, and no data is discarded.

       If no data is available to be received, _r_e_c_v waits  for  a
       message  to  arrive  unless  non-blocking mode is enabled.
       You can enable non-blocking mode by setting  the  O_NDELAY
       flag  using  _f_c_n_t_l.  O_NDELAY is defined in <ffccnnttll..hh>.  If
       non-blocking mode is enabled, the _r_e_c_v  request  completes
       in one of three ways:

              +o  If there is enough data available to satisfy the
                 entire  request,  _r_e_c_v  completes  successfully,
                 having read all the data, and returns the number
                 of bytes read.

              +o  If there is not enough data available to satisfy
                 the entire request, _r_e_c_v completes successfully,
                 having  read  as  much  data  as  possible,  and
                 returns the number of bytes it was able to read.

              +o  If there is no data  available,  _r_e_c_v  completes
                 successfully,  having  read no data, and returns
                 0.

       If the O_NDELAY flag is cleared using _f_c_n_t_l_,  non-blocking
       I/O,  if  previously  enabled, is disabled.  In this case,
       _r_e_c_v always executes completely  (blocking  as  necessary)
       and returns the number of bytes read.

       The _s_e_l_e_c_t(3) call can be used to determine when more data
       arrives by selecting the socket for reading.

       The _f_l_a_g_s parameter can be set to MSG_PEEK, MSG_OOB, both,
       or  zero.   If it is set to MSG_PEEK, any data returned to
       the user still is treated as if it had not been read.  The
       next  _r_e_c_v  re-reads  the  same data.  The MSG_OOB flag is
       used to alert the other process with  an  urgent  message,
       using a logically independent transmission channel associ-
       ated with a pair of connected stream  sockets.   Refer  to
       SEE  ALSO below for details.  MSG_PEEK and MSG_OOB are not
       supported for AF_UNIX sockets.

       A _r_e_a_d(3) call made to a socket  behaves  in  exactly  the
       same way as a _r_e_c_v with _f_l_a_g_s set to zero.

RREETTUURRNN VVAALLUUEE
       If the _r_e_c_v or _r_e_c_v_f_r_o_m call is successful, it returns the
       number of bytes  received.   If  the  call  fails,  -1  is
       returned and an error code is stored in eerrrrnnoo.

DDIIAAGGNNOOSSTTIICCSS
       The call to _r_e_c_v or _r_e_c_v_f_r_o_m fail if:

              [EBADF]             The  argument  _s  is an invalid



                             MiNT-Net                           2





recv(3)                                                   recv(3)


                                  descriptor.

              [EINVAL]            The argument _s is not a socket.

              [EINTR]             The  receive was interrupted by
                                  delivery of a signal before any
                                  data   was  available  for  the
                                  receive.

              [ENOTCONN]          Receive on a SOCK_STREAM socket
                                  that is not yet connected.

              [EOPNOTSUPP]        The  MSG_OOB  or  MSG_PEEK flag
                                  was set for any AF_UNIX socket.
                                  Neither MSG_PEEK nor MSG_OOB is
                                  supported for AF_UNIX  sockets.

SSEEEE AALLSSOO
       getsockopt(3), read(3), select(3), send(3), socket(3).






































                             MiNT-Net                           3


