summaryrefslogtreecommitdiff
path: root/doc/s6-tcpserverd.html
blob: 6600a7b5bba7b6f6b93a9861f463a390992200a0 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Language" content="en" />
    <title>s6-networking: the s6-tcpserverd program</title>
    <meta name="Description" content="s6-networking: the s6-tcpserverd program" />
    <meta name="Keywords" content="s6-networking s6-tcpserverd tcpserver ucspi tcp server super-server ipv4 ipv6 TCP/IP" />
    <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
  </head>
<body>

<p>
<a href="index.html">s6-networking</a><br />
<a href="//skarnet.org/software/">Software</a><br />
<a href="//skarnet.org/">skarnet.org</a>
</p>

<h1> The <tt>s6-tcpserverd</tt> program </h1>

<p>
<tt>s6-tcpserverd</tt> is the serving part of the
<a href="s6-tcpserver.html">s6-tcpserver</a> super-server.
It assumes that its stdin is a bound and listening TCP/IP socket,
and it accepts connections from clients connecting to it,
spawning a program to handle each connection.
</p>

<h2> Interface </h2>

<pre>
     s6-tcpserverd [ -1 ] [ -v <em>verbosity</em> ] [ -c <em>maxconn</em> ] [ -C <em>localmaxconn</em> ] <em>prog...</em>
</pre>

<ul>
 <li> s6-tcpserverd accepts connections from clients to an already
bound and listening TCP socket which is its standard input. </li>
 <li> For every TCP connection to this socket, it
spawns a <em>prog...</em> child with stdin reading from the network
socket and stdout writing to it. </li>
 <li> Depending on the verbosity level, it logs what it does to stderr. </li>
 <li> It runs until killed by a signal. Depending on the received
signal, it may kill its children before exiting. </li>
</ul>

<h2> Environment variables </h2>

<p>
 For each connection, an instance of <em>prog...</em> is spawned with
the following variables set:
</p>

<ul>
 <li> PROTO: always set to TCP </li>
 <li> TCPLOCALIP: set to the server socket's address </li>
 <li> TCPLOCALPORT: set to the server socket's port </li>
 <li> TCPREMOTEIP: set to the client socket's address </li>
 <li> TCPREMOTEPORT: set to the client socket's port </li>
 <li> TCPCONNNUM: set to the number of connections originating from
the same IP address </li>
</ul>

<h2> Options </h2>

<ul>
 <li> <tt>-1</tt>&nbsp;: write the local port, followed by newline,
to stdout, and close stdout, right before entering the client-accepting loop.
If stdout is suitably redirected, this can be used by monitoring
programs to check when the server is accepting connections. This can be
used with s6's <a href="//skarnet.org/software/s6/notifywhenup.html">readiness
notification mechanism</a> to make sure subsequent services do not start
before the server is ready. </li>
 <li> <tt>-v&nbsp;<em>verbosity</em></tt>&nbsp;: be more or less verbose.
By default, <em>verbosity</em> is 1: print warning messages to stderr.
0 means only print fatal error messages ; 2 means print status and
connection information for every client. </li>
 <li> <tt>-c&nbsp;<em>maxconn</em></tt>&nbsp;: accept at most
<em>maxconn</em> concurrent connections. Default is 40. It is
impossible to set it higher than 16384. </li>
 <li> <tt>-C&nbsp;<em>localmaxconn</em></tt>&nbsp;: accept at most
<em>localmaxconn</em> connections from the same IP address.
Default is 40. It is impossible to set it higher than <em>maxconn</em>. </li>
</ul>

<h2> Signals </h2>

<ul>
 <li> SIGTERM: exit. </li>
 <li> SIGHUP: send a SIGTERM and a SIGCONT to all children. </li>
 <li> SIGQUIT: send a SIGTERM and a SIGCONT to all children, then exit. </li>
 <li> SIGABRT: send a SIGKILL to all children, then exit. </li>
</ul>

<h2> Notes </h2>

<ul>
 <li> Unlike its ancestor
<a href="https://cr.yp.to/ucspi-tcp/tcpserver.html">tcpserver</a>,
s6-tcpserverd performs just the bare minimum: the point is to have a
small and very fast process to serve connections with the least
possible overhead. Features such as access control and DNS resolution
are provided via the <a href="s6-tcpserver-access.html">s6-tcpserver-access</a>
program. </li>
 <li> s6-tcpserverd is meant to be execve'd into by a program that gets
the listening socket. That program is normally
<a href="s6-tcpserver-socketbinder.html">s6-tcpserver-socketbinder</a>,
which creates the socket itself; but it can be a different one if the
socket is to be retrieved by another means, for instance by fd-passing
from a fd-holding daemon (some people call this "socket activation"). </li>
</ul>

</body>
</html>