
accept(+Stream, -From, ?NewStream)

   Accepts a connection for a stream socket and creates a new socket which can
be used for I/O.



Arguments
   Stream              Stream handle or alias (atom)
   From                A term unifiable with a structure atom/integer.
   NewStream           Atom, structure or variable.

Type
   Stream I/O

Description
   accept/3 is a direct link to the accept(2) socket system call.
   Stream must be a socket stream created with socket/3 or new_socket_server/3
   of the type stream, listening for connections.  accept/3 blocks until
   there is a connection request from another process, and then it creates
   a new socket stream NewStream with the same properties as Stream, which
   can be then used for communication with the connecting process.  The
   Stream socket remains open and listening for further connections.


   In the internet domain, From is unified with the address of the
   connecting process in the form HostName/Port.  In the unix domain, From
   is unified with an empty atom ''.


   When instantiated, NewStream must be a symbolic stream name, i.e.  an
   atom.  The stream can also be specified as sigio(NewStream).  In this
   case the socket is created and in addition it is instructed to send the
   signal io each time new data appears in it.


   Stream sockets are connected using the standard sequence, i.e.
   socket/3, bind/2, listen/2 and accept/3 on the server and socket/3 and
   connect/2 on the client.  After the sockets are connected, both
   processes can use them for reading and writing.




Modes and Determinism
   accept(+, -, -) is det
   accept(+, -, +) is det

Exceptions
     4 --- Stream is not instantiated.
     5 --- Stream is instantiated, but not to an atom or a sigio/1    structure.
     5 --- From is instantiated but not to an atom or a structure.
   170 --- It was not possible to execute the system call.

Examples
   
Success:
      socket(internet, stream, s), bind(s, Addr), listen(s, 1),
      accept(s, From, news).

Error:
      accept(s, From, 6)            (Error 5).
      socket(internet, datagram, s), bind(s, Addr), listen(s, 2),
      accept(s, From, news)         (Error 170).





See Also
   socket / 3, bind / 2, listen / 2, connect / 2
