summaryrefslogtreecommitdiffstats
path: root/docs/nspr/reference/pr_accept.rst
blob: eb1b1ad3ed41d9f980823eee5c5e4b34b7f7da7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
PR_Accept
=========

Accepts a connection on a specified socket.


Syntax
------

.. code::

   #include <prio.h>

   PRFileDesc* PR_Accept(
     PRFileDesc *fd,
     PRNetAddr *addr,
     PRIntervalTime timeout);


Parameters
~~~~~~~~~~

The function has the following parameters:

``fd``
   A pointer to a :ref:`PRFileDesc` object representing the rendezvous
   socket on which the caller is willing to accept new connections.
``addr``
   A pointer to a structure of type :ref:`PRNetAddr`. On output, this
   structure contains the address of the connecting entity.
``timeout``
   A value of type :ref:`PRIntervalTime` specifying the time limit for
   completion of the accept operation.


Returns
~~~~~~~

The function returns one of the following values:

-  Upon successful acceptance of a connection, a pointer to a new
   :ref:`PRFileDesc` structure representing the newly accepted connection.
-  If unsuccessful, ``NULL``. Further information can be obtained by
   calling :ref:`PR_GetError`.


Description
-----------

The socket ``fd`` is a rendezvous socket that has been bound to an
address with :ref:`PR_Bind` and is listening for connections after a call
to :ref:`PR_Listen`. :ref:`PR_Accept` accepts the first connection from the
queue of pending connections and creates a new socket for the newly
accepted connection. The rendezvous socket can still be used to accept
more connections.

If the ``addr`` parameter is not ``NULL``, :ref:`PR_Accept` stores the
address of the connecting entity in the :ref:`PRNetAddr` object pointed to
by ``addr``.

:ref:`PR_Accept` blocks the calling thread until either a new connection is
successfully accepted or an error occurs. If the timeout parameter is
not ``PR_INTERVAL_NO_TIMEOUT`` and no pending connection can be accepted
before the time limit, :ref:`PR_Accept` returns ``NULL`` with the error
code ``PR_IO_TIMEOUT_ERROR``.