Use .Fn for function names in some manual pages.
[dragonfly.git] / lib / libc / sys / listen.2
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     From: @(#)listen.2      8.2 (Berkeley) 12/11/93
29 .\" $FreeBSD: src/lib/libc/sys/listen.2,v 1.12.2.9 2002/05/09 02:24:40 silby Exp $
30 .\"
31 .Dd November 3, 1995
32 .Dt LISTEN 2
33 .Os
34 .Sh NAME
35 .Nm listen
36 .Nd listen for connections on a socket
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/types.h
41 .In sys/socket.h
42 .Ft int
43 .Fn listen "int s" "int backlog"
44 .Sh DESCRIPTION
45 To accept connections, a socket
46 is first created with
47 .Xr socket 2 ,
48 a willingness to accept incoming connections and
49 a queue limit for incoming connections are specified with
50 .Fn listen ,
51 and then the connections are
52 accepted with
53 .Xr accept 2 .
54 The
55 .Fn listen
56 call applies only to sockets of type
57 .Dv SOCK_STREAM
58 or
59 .Dv SOCK_SEQPACKET .
60 .Pp
61 The
62 .Fa backlog
63 parameter defines the maximum length the queue of
64 pending connections may grow to.
65 If a connection
66 request arrives with the queue full the client may
67 receive an error with an indication of
68 .Er ECONNREFUSED ,
69 or, in the case of TCP, the connection will be
70 silently dropped.
71 .Pp
72 Note that before
73 .Fx 4.5
74 and the introduction of the syncache, the
75 .Fa backlog
76 parameter also determined the length of the incomplete
77 connection queue, which held TCP sockets in the process
78 of completing TCP's 3-way handshake.
79 These incomplete connections
80 are now held entirely in the syncache, which is unaffected by
81 queue lengths.
82 Inflated
83 .Fa backlog
84 values to help handle denial
85 of service attacks are no longer necessary.
86 .Pp
87 The
88 .Xr sysctl 3
89 MIB variable
90 .Dq Va kern.ipc.somaxconn
91 specifies a hard limit on
92 .Fa backlog ;
93 if a value greater than
94 .Va kern.ipc.somaxconn
95 or less than zero is specified,
96 .Fa backlog
97 is silently forced to
98 .Va kern.ipc.somaxconn .
99 .Sh INTERACTION WITH ACCEPT FILTERS
100 When accept filtering is used on a socket, a second queue will
101 be used to hold sockets that have connected, but have not yet
102 met their accept filtering criteria.
103 Once the criteria has been
104 met, these sockets will be moved over into the completed connection
105 queue to be
106 .Fn accept Ns ed.
107 If this secondary queue is full and a
108 new connection comes in, the oldest socket which has not yet met
109 its accept filter criteria will be terminated.
110 .Pp
111 This secondary queue, like the primary listen queue, is sized
112 according to the
113 .Fa backlog
114 parameter.
115 .Sh RETURN VALUES
116 .Rv -std listen
117 .Sh ERRORS
118 .Fn Listen
119 will fail if:
120 .Bl -tag -width Er
121 .It Bq Er EBADF
122 The argument
123 .Fa s
124 is not a valid descriptor.
125 .It Bq Er ENOTSOCK
126 The argument
127 .Fa s
128 is not a socket.
129 .It Bq Er EOPNOTSUPP
130 The socket is not of a type that supports the operation
131 .Fn listen .
132 .El
133 .Sh SEE ALSO
134 .Xr accept 2 ,
135 .Xr connect 2 ,
136 .Xr socket 2 ,
137 .Xr sysctl 3 ,
138 .Xr sysctl 8 ,
139 .Xr accept_filter 9
140 .Sh HISTORY
141 The
142 .Fn listen
143 function call appeared in
144 .Bx 4.2 .
145 The ability to configure the maximum
146 .Fa backlog
147 at run-time, and to use a negative
148 .Fa backlog
149 to request the maximum allowable value, was introduced in
150 .Fx 2.2 .