copyediting for Usenix manuals
[unix-history] / usr / src / lib / libc / sys / listen.2
CommitLineData
3f6f0ccf
KB
1.\" Copyright (c) 1983, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
cf65baf0 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
da268306 5.\"
653ba8b6 6.\" @(#)listen.2 8.2 (Berkeley) %G%
cf65baf0 7.\"
931b8415
CL
8.Dd
9.Dt LISTEN 2
10.Os BSD 4.2
11.Sh NAME
12.Nm listen
13.Nd listen for connections on a socket
14.Sh SYNOPSIS
15.Fd #include <sys/socket.h>
16.Ft int
17.Fn listen "int s" "int backlog"
18.Sh DESCRIPTION
cf65baf0
KM
19To accept connections, a socket
20is first created with
931b8415 21.Xr socket 2 ,
3fa31615
MK
22a willingness to accept incoming connections and
23a queue limit for incoming connections are specified with
931b8415 24.Fn listen ,
cf65baf0
KM
25and then the connections are
26accepted with
931b8415 27.Xr accept 2 .
cf65baf0 28The
931b8415 29.Fn listen
cf65baf0 30call applies only to sockets of type
931b8415 31.Dv SOCK_STREAM
cf65baf0 32or
931b8415
CL
33.Dv SOCK_SEQPACKET.
34.Pp
cf65baf0 35The
931b8415 36.Fa backlog
cf65baf0
KM
37parameter defines the maximum length the queue of
38pending connections may grow to.
39If a connection
3fa31615 40request arrives with the queue full the client may
931b8415
CL
41receive an error with an indication of
42.Er ECONNREFUSED ,
3fa31615
MK
43or, if the underlying protocol supports retransmission,
44the request may be ignored so that retries may succeed.
931b8415
CL
45.Sh RETURN VALUES
46A 0 return value indicates success; -1 indicates an error.
47.Sh ERRORS
653ba8b6
KM
48.Fn Listen
49will fail if:
931b8415
CL
50.Bl -tag -width [EOPNOTSUPP]
51.It Bq Er EBADF
52The argument
53.Fa s
54is not a valid descriptor.
55.It Bq Er ENOTSOCK
56The argument
57.Fa s
58is not a socket.
59.It Bq Er EOPNOTSUPP
60The socket is not of a type that supports the operation
61.Fn listen .
62.El
63.Sh SEE ALSO
64.Xr accept 2 ,
65.Xr connect 2 ,
66.Xr socket 2
67.Sh BUGS
cf65baf0 68The
931b8415 69.Fa backlog
cf65baf0 70is currently limited (silently) to 5.
931b8415
CL
71.Sh HISTORY
72The
73.Nm
74function call appeared in
75.Bx 4.2 .