


send(3)                                                   send(3)


NNAAMMEE
       send, sendto - send a message from a socket

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

       iinntt sseenndd((iinntt ss,, vvooiidd **mmssgg,, ssiizzee__tt lleenn,, iinntt ffllaaggss));;


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

       iinntt sseennddttoo((iinntt ss,, vvooiidd **mmssgg,, ssiizzee__tt lleenn,, iinntt ffllaaggss,,
              ssttrruucctt ssoocckkaaddddrr **ttoo,, ssiizzee__tt ttoolleenn));;

DDEESSCCRRIIPPTTIIOONN
       _s_e_n_d  and _s_e_n_d_t_o are used to transmit a message to another
       socket.  _s_e_n_d can be used only when the  socket  is  in  a
       connected state, whereas _s_e_n_d_t_o can be used at any time.

       _s  is  a  socket  descriptor  that specifies the socket on
       which the message will be sent.  _m_s_g points to the  buffer
       containing the message.

       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)).  In this case, any destination specified  by  _t_o
       is   ignored.    For   connectionless   sockets,  such  as
       SOCK_DGRAM, _s_e_n_d_t_o must be  used  unless  the  destination
       address  has already been specified by _c_o_n_n_e_c_t(3).  If the
       destination address has been specified and _s_e_n_d_t_o is used,
       an error results if any address is specified by _t_o.

       The address of the target is contained in a socket address
       structure pointed at by _t_o, with _t_o_l_e_n specifying the size
       of the structure.

       If a _s_e_n_d_t_o is attempted on a SOCK_DGRAM socket before any
       local address has been bound to it, the  system  automati-
       cally  selects a local address to be used for the message.
       In this case, there is no guarantee that  the  same  local
       address will be used for successive _s_e_n_d_t_o requests on the
       same socket.

       The length of the message is given by _l_e_n, in bytes.   The
       length  of data actually sent is returned.  If the message
       is too long to pass atomically through the underlying pro-
       tocol, the message is not transmitted, -1 is returned, and
       eerrrrnnoo is set to EMSGSIZE.  For  SOCK_DGRAM  sockets,  this
       size  is  limited by the implementation (see the DEPENDEN-
       CIES section below).  Otherwise there is no size limit.

       No indication of failure  to  deliver  is  implicit  in  a



                             MiNT-Net                           1





send(3)                                                   send(3)


       _s_e_n_d/_s_e_n_d_t_o.   Return  values of -1 indicate some locally-
       detected errors.

       If no buffer space is available to hold  the  data  to  be
       transmitted,  _s_e_n_d  blocks  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  _s_e_n_d
       request completes in one of three ways:

              +o  If there is enough space available in the system
                 to buffer all the data, _s_e_n_d completes  success-
                 fully,  having  written out all of the data, and
                 returns the number of bytes written.

              +o  If there is not enough space in  the  buffer  to
                 write  out  the  entire  request, _s_e_n_d completes
                 successfully, having written  as  much  data  as
                 possible, and returns the number of bytes it was
                 able to write.

              +o  If there is no space in the system to buffer any
                 of the data, _s_e_n_d completes successfully, having
                 written no data, and returns 0.

       If the O_NDELAY flag is cleared using _f_c_n_t_l_,  non-blocking
       I/O  is  disabled.  In this case, the _s_e_n_d always executes
       completely (blocking as necessary) and returns the  number
       of bytes written.  The default is that non-blocking I/O is
       not enabled.

       The supported values for _f_l_a_g_s are zero,  or  MSG_OOB  (to
       send  out-of-band data).  A _w_r_i_t_e(3) call made to a socket
       behaves in exactly the same way as _s_e_n_d with _f_l_a_g_s set  to
       zero.  MSG_OOB is not supported for AF_UNIX sockets.

       The  _s_e_l_e_c_t(3)  call  can  be used to determine when it is
       possible to send more data.

DDEEPPEENNDDEENNCCIIEESS
       DDeeffaauulltt and mmaaxxiimmuumm buffer  sizes  are  protocol-specific.
       The  buffer  size can be set by calling _s_e_t_s_o_c_k_o_p_t(3) with
       SO_SNDBUF.

RREETTUURRNN VVAALLUUEE
       If successful, the call returns the number of bytes  sent.
       If the call fails, -1 is returned.

DDIIAAGGNNOOSSTTIICCSS
       _s_e_n_d or _s_e_n_d_t_o fails if:

              [EBADF]               An   invalid  descriptor  was
                                    specified.




                             MiNT-Net                           2





send(3)                                                   send(3)


              [EMSGSIZE]            The socket requires that mes-
                                    sages be sent atomically, and
                                    the size of the message to be
                                    sent made this impossible.

              [EINTR]               The operation was interrupted
                                    by a signal before  any  data
                                    were sent.  (If some data was
                                    sent, _s_e_n_d returns the number
                                    of bytes sent before the sig-
                                    nal, and EINTR is not given.)

              [EINVAL]              The _l_e_n or _t_o_l_e_n parameter is
                                    invalid or the specified des-
                                    tination   address   is   not
                                    valid.  The argument _s is not
                                    a socket.

              [EDESTADDRREQ]        The  _t_o  parameter  needs  to
                                    specify a destination address
                                    for the message.

              [ENOTCONN]            A  _s_e_n_d  on  a socket that is
                                    not connected, or a _s_e_n_d on a
                                    socket that has not completed
                                    the connect sequence with its
                                    peer,  or  is  no longer con-
                                    nected to its peer.

              [EISCONN]             An address was  specified  by
                                    _t_o  for  a  SOCK_DGRAM socket
                                    which is already connected.

              [EAFNOSUPPORT]        Requested  address  does  not
                                    match  the  address family of
                                    this socket.

              [EPIPE] and SIGPIPE signal
                                    An attempt was made  to  send
                                    on  a  socket  that  was con-
                                    nected,  but  the  connection
                                    has been shut down, either by
                                    the remote peer  or  by  this
                                    side of the connection.  Note
                                    that the default  action  for
                                    SIGPIPE,  unless  the process
                                    has established a signal han-
                                    dler  for  this signal, is to
                                    terminate the process.

              [EOPNOTSUPP]          The MSG_OOB flag  was  speci-
                                    fied; it is not supported for
                                    AF_UNIX sockets.




                             MiNT-Net                           3





send(3)                                                   send(3)


SSEEEE AALLSSOO
       getsockopt(3),    recv(3),    select(3),    setsockopt(3),
       socket(3).






















































                             MiNT-Net                           4


