TEXT   10

accept.txt

Guest on 1st August 2021 05:49:14 PM

  1. NAME
  2.        accept - accept a connection on a socket
  3.  
  4.  
  5.  
  6. SYNOPSIS
  7.        #include <sys/types.h>
  8.        #include <sys/socket.h>
  9.        int accept(int s, struct sockaddr *addr, int *addrlen);
  10.  
  11.  
  12.  
  13. DESCRIPTION
  14.        The  argument  s  is  a  socket that has been created with
  15.        socket(2), bound to an address with bind(2), and  is  lis-
  16.        tening  for  connections  after  a  listen(2).  The accept
  17.        argument extracts the  first  connection  request  on  the
  18.        queue  of  pending  connections, creates a new socket with
  19.        the same properties of s and allocates a new file descrip-
  20.        tor for the socket.  If no pending connections are present
  21.        on the queue, and the socket is not marked  as  non-block-
  22.        ing,  accept  blocks the caller until a connection is pre-
  23.        sent.  If the socket is marked non-blocking and no pending
  24.        connections  are  present  on the queue, accept returns an
  25.        error as described below.  The accepted socket may not  be
  26.        used  to  accept  more connections.  The original socket s
  27.        remains open.
  28.  
  29.        The argument addr is a result parameter that is filled  in
  30.        with the address of the connecting entity, as known to the
  31.        communications layer.  The exact format of the addr param-
  32.        eter  is  determined by the domain in which the communica-
  33.        tion is occurring.  The addrlen is a value-result  parame-
  34.        ter;  it  should  initially  contain  the  amount of space
  35.        pointed to by addr; on return it will contain  the  actual
  36.        length  (in  bytes) of the address returned.  This call is
  37.        used with connection-based socket  types,  currently  with
  38.        SOCK_STREAM.
  39.  
  40.        It  is  possible to select(2) a socket for the purposes of
  41.        doing an accept by selecting it for read.
  42.  
  43.        For certain protocols which require an explicit  confirma-
  44.        tion,  such as ISO or DATAKIT, accept can be thought of as
  45.        merely dequeuing  the  next  connection  request  and  not
  46.        implying  confirmation.   Confirmation can be implied by a
  47.        normal read or write  on  the  new  file  descriptor,  and
  48.        rejection can be implied by closing the new socket.
  49.  
  50.        One  can  obtain user connection request data without con-
  51.        firming the connection by issuing a recvmsg(2)  call  with
  52.        an  msg_iovlen  of  0 and a non-zero msg_controllen, or by
  53.        issuing a getsockopt(2) request.  Similarly, one can  pro-
  54.        vide  user  connection  rejection information by issuing a
  55.        sendmsg(2) call with providing only the  control  informa-
  56.        tion, or by calling setsockopt(2).
  57.  
  58.  
  59.  
  60.  
  61. RETURN VALUES
  62.        The  call returns -1 on error.  If it succeeds, it returns
  63.        a non-negative  integer  that  is  a  descriptor  for  the
  64.        accepted socket.
  65.  
  66.  
  67.  
  68. ERRORS
  69.        EBADF   The descriptor is invalid.
  70.  
  71.        ENOTSOCK
  72.                The descriptor references a file, not a socket.
  73.  
  74.        EOPNOTSUPP
  75.                The  referenced socket is not of type SOCK_STREAM.
  76.  
  77.        EFAULT  The addr parameter is not in a  writable  part  of
  78.                the user address space.
  79.  
  80.        EWOULDBLOCK
  81.                The  socket  is marked non-blocking and no connec-
  82.                tions are present to be accepted.
  83.  
  84.  
  85.  
  86. HISTORY
  87.        The accept function appeared in BSD 4.2.
  88.  
  89.  
  90.  
  91. SEE ALSO
  92.        bind(2), connect(2), listen(2), select(2), socket(2)

Raw Paste


Login or Register to edit or fork this paste. It's free.