File: pr_opentcpsocket.rst

package info (click to toggle)
thunderbird 1%3A115.16.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,476,252 kB
  • sloc: cpp: 6,972,150; javascript: 5,209,211; ansic: 3,507,222; python: 1,137,609; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,485; makefile: 22,152; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (59 lines) | stat: -rw-r--r-- 1,844 bytes parent folder | download | duplicates (18)
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
PR_OpenTCPSocket
================

Creates a new TCP socket of the specified address family.


Syntax
------

.. code::

   #include <prio.h>

   PRFileDesc* PR_OpenTCPSocket(PRIntn af);


Parameters
~~~~~~~~~~

The function has the following parameters:

``af``
   The address family of the new TCP socket. Can be ``PR_AF_INET``
   (IPv4), ``PR_AF_INET6`` (IPv6), or ``PR_AF_LOCAL`` (Unix domain,
   supported on POSIX systems only).


Returns
~~~~~~~

The function returns one of the following values:

-  Upon successful completion, a pointer to the :ref:`PRFileDesc` object
   created for the newly opened TCP socket.
-  If the creation of a new TCP socket failed, ``NULL``.


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

TCP (Transmission Control Protocol) is a connection-oriented, reliable
byte-stream protocol of the TCP/IP protocol suite. :ref:`PR_OpenTCPSocket`
creates a new TCP socket of the address family ``af``. A TCP connection
is established by a passive socket (the server) accepting a connection
setup request from an active socket (the client). Typically, the server
binds its socket to a well-known port with :ref:`PR_Bind`, calls
:ref:`PR_Listen` to start listening for connection setup requests, and
calls :ref:`PR_Accept` to accept a connection. The client makes a
connection request using :ref:`PR_Connect`.

After a connection is established, the client and server may send and
receive data between each other. To receive data, one can call
:ref:`PR_Read` or :ref:`PR_Recv`. To send data, one can call :ref:`PR_Write`,
:ref:`PR_Writev`, :ref:`PR_Send`, or :ref:`PR_TransmitFile`. :ref:`PR_AcceptRead` is
suitable for use by the server to accept a new client connection and
read the client's first request in one function call.

A TCP connection can be shut down by :ref:`PR_Shutdown`, and the sockets
should be closed by :ref:`PR_Close`.