update from Donn -- fixes for pcc
[unix-history] / usr / src / lib / libc / sys / listen.2
CommitLineData
931b8415 1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
da268306 2.\" All rights reserved.
cf65baf0 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
da268306 5.\"
931b8415 6.\" @(#)listen.2 6.5 (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
48.Fn Listen will fail if:
49.Bl -tag -width [EOPNOTSUPP]
50.It Bq Er EBADF
51The argument
52.Fa s
53is not a valid descriptor.
54.It Bq Er ENOTSOCK
55The argument
56.Fa s
57is not a socket.
58.It Bq Er EOPNOTSUPP
59The socket is not of a type that supports the operation
60.Fn listen .
61.El
62.Sh SEE ALSO
63.Xr accept 2 ,
64.Xr connect 2 ,
65.Xr socket 2
66.Sh BUGS
cf65baf0 67The
931b8415 68.Fa backlog
cf65baf0 69is currently limited (silently) to 5.
931b8415
CL
70.Sh HISTORY
71The
72.Nm
73function call appeared in
74.Bx 4.2 .