tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pr_opentcpsocket.rst (1844B)


      1 PR_OpenTCPSocket
      2 ================
      3 
      4 Creates a new TCP socket of the specified address family.
      5 
      6 
      7 Syntax
      8 ------
      9 
     10 .. code::
     11 
     12   #include <prio.h>
     13 
     14   PRFileDesc* PR_OpenTCPSocket(PRIntn af);
     15 
     16 
     17 Parameters
     18 ~~~~~~~~~~
     19 
     20 The function has the following parameters:
     21 
     22 ``af``
     23   The address family of the new TCP socket. Can be ``PR_AF_INET``
     24   (IPv4), ``PR_AF_INET6`` (IPv6), or ``PR_AF_LOCAL`` (Unix domain,
     25   supported on POSIX systems only).
     26 
     27 
     28 Returns
     29 ~~~~~~~
     30 
     31 The function returns one of the following values:
     32 
     33 -  Upon successful completion, a pointer to the :ref:`PRFileDesc` object
     34   created for the newly opened TCP socket.
     35 -  If the creation of a new TCP socket failed, ``NULL``.
     36 
     37 
     38 Description
     39 -----------
     40 
     41 TCP (Transmission Control Protocol) is a connection-oriented, reliable
     42 byte-stream protocol of the TCP/IP protocol suite. :ref:`PR_OpenTCPSocket`
     43 creates a new TCP socket of the address family ``af``. A TCP connection
     44 is established by a passive socket (the server) accepting a connection
     45 setup request from an active socket (the client). Typically, the server
     46 binds its socket to a well-known port with :ref:`PR_Bind`, calls
     47 :ref:`PR_Listen` to start listening for connection setup requests, and
     48 calls :ref:`PR_Accept` to accept a connection. The client makes a
     49 connection request using :ref:`PR_Connect`.
     50 
     51 After a connection is established, the client and server may send and
     52 receive data between each other. To receive data, one can call
     53 :ref:`PR_Read` or :ref:`PR_Recv`. To send data, one can call :ref:`PR_Write`,
     54 :ref:`PR_Writev`, :ref:`PR_Send`, or :ref:`PR_TransmitFile`. :ref:`PR_AcceptRead` is
     55 suitable for use by the server to accept a new client connection and
     56 read the client's first request in one function call.
     57 
     58 A TCP connection can be shut down by :ref:`PR_Shutdown`, and the sockets
     59 should be closed by :ref:`PR_Close`.