xref: /original-bsd/lib/libc/sys/listen.2 (revision 93bede30)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)listen.2	8.2 (Berkeley) 12/11/93
7.\"
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
19To accept connections, a socket
20is first created with
21.Xr socket 2 ,
22a willingness to accept incoming connections and
23a queue limit for incoming connections are specified with
24.Fn listen ,
25and then the connections are
26accepted with
27.Xr accept 2 .
28The
29.Fn listen
30call applies only to sockets of type
31.Dv SOCK_STREAM
32or
33.Dv SOCK_SEQPACKET.
34.Pp
35The
36.Fa backlog
37parameter defines the maximum length the queue of
38pending connections may grow to.
39If a connection
40request arrives with the queue full the client may
41receive an error with an indication of
42.Er ECONNREFUSED ,
43or, if the underlying protocol supports retransmission,
44the request may be ignored so that retries may succeed.
45.Sh RETURN VALUES
46A 0 return value indicates success; -1 indicates an error.
47.Sh ERRORS
48.Fn Listen
49will fail if:
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
68The
69.Fa backlog
70is currently limited (silently) to 5.
71.Sh HISTORY
72The
73.Nm
74function call appeared in
75.Bx 4.2 .
76