update NEWS
[manpages-zh.git] / raw / man2 / listen.2
blobe6b0cedd477f35d2c3af6f337e1e1bb329efb264
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" 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. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\" Modified Fri Jul 23 22:07:54 1993 by Rik Faith <faith@cs.unc.edu>
33 .\" Modified 950727 by aeb, following a suggestion by Urs Thuermann
34 .\" <urs@isnogud.escape.de>
35 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified 1998 by Andi Kleen 
37 .\" Modified 11 May 2001 by Sam Varshavchik <mrsam@courier-mta.com>
38 .\"
39 .TH LISTEN 2 1993-07-23 "BSD Man Page" "Linux Programmer's Manual"
40 .SH NAME
41 listen \- listen for connections on a socket
42 .SH SYNOPSIS
43 .B #include <sys/socket.h>
44 .sp
45 .BI "int listen(int " s ", int " backlog );
46 .SH DESCRIPTION
47 To accept connections, a socket is first created with
48 .BR socket (2),
49 a willingness to accept incoming connections and a queue limit for incoming
50 connections are specified with
51 .BR listen ,
52 and then the connections are
53 accepted with
54 .BR accept (2).
55 The
56 .B listen
57 call applies only to sockets of type
58 .B SOCK_STREAM
60 .BR SOCK_SEQPACKET .
61 .PP
62 The
63 .I backlog
64 parameter defines the maximum length the queue of pending connections may
65 grow to.  If a connection request arrives with the queue full the client
66 may receive an error with an indication of
67 .B ECONNREFUSED
68 or, if the underlying protocol supports retransmission, the request may be
69 ignored so that retries succeed.
70 .SH NOTES
71 The behaviour of the 
72 .I backlog 
73 parameter on TCP sockets changed with Linux 2.2.
74 Now it specifies the queue length for 
75 .I completely 
76 established sockets waiting to be accepted, instead of the number of incomplete
77 connection requests. The maximum length of the queue for incomplete sockets
78 can be set using the 
79 .B tcp_max_syn_backlog
80 sysctl.
81 When syncookies are enabled there is no logical maximum 
82 length and this sysctl setting is ignored.
83 See 
84 .BR tcp (7)
85 for more information.
87 .SH "RETURN VALUE"
88 On success, zero is returned.  On error, \-1 is returned, and
89 .I errno
90 is set appropriately.
91 .SH ERRORS
92 .TP
93 .B EADDRINUSE
94 Another socket is already listening on the same port.
95 .TP
96 .B EBADF
97 The argument
98 .I s
99 is not a valid descriptor.
101 .B ENOTSOCK
102 The argument
103 .I s
104 is not a socket.
106 .B EOPNOTSUPP
107 The socket is not of a type that supports the
108 .B listen 
109 operation.
110 .SH "CONFORMING TO"
111 Single Unix, 4.4BSD, POSIX 1003.1g draft. The
112 .B listen
113 function call first appeared in 4.2BSD. 
114 .SH BUGS
115 If the socket is of type 
116 .BR AF_INET , 
117 and the
118 .I backlog
119 argument is greater
120 than the constant 
121 .B SOMAXCONN 
122 (128 in Linux 2.0 & 2.2), it is silently truncated
123 to 
124 .BR SOMAXCONN . 
125 Don't rely on this value in portable applications since BSD
126 (and some BSD-derived systems) limit the backlog to 5.
127 .SH "SEE ALSO"
128 .BR accept (2),
129 .BR connect (2),
130 .BR socket (2)