Commit | Line | Data |
---|---|---|
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 |
19 | To accept connections, a socket |
20 | is first created with | |
931b8415 | 21 | .Xr socket 2 , |
3fa31615 MK |
22 | a willingness to accept incoming connections and |
23 | a queue limit for incoming connections are specified with | |
931b8415 | 24 | .Fn listen , |
cf65baf0 KM |
25 | and then the connections are |
26 | accepted with | |
931b8415 | 27 | .Xr accept 2 . |
cf65baf0 | 28 | The |
931b8415 | 29 | .Fn listen |
cf65baf0 | 30 | call applies only to sockets of type |
931b8415 | 31 | .Dv SOCK_STREAM |
cf65baf0 | 32 | or |
931b8415 CL |
33 | .Dv SOCK_SEQPACKET. |
34 | .Pp | |
cf65baf0 | 35 | The |
931b8415 | 36 | .Fa backlog |
cf65baf0 KM |
37 | parameter defines the maximum length the queue of |
38 | pending connections may grow to. | |
39 | If a connection | |
3fa31615 | 40 | request arrives with the queue full the client may |
931b8415 CL |
41 | receive an error with an indication of |
42 | .Er ECONNREFUSED , | |
3fa31615 MK |
43 | or, if the underlying protocol supports retransmission, |
44 | the request may be ignored so that retries may succeed. | |
931b8415 CL |
45 | .Sh RETURN VALUES |
46 | A 0 return value indicates success; -1 indicates an error. | |
47 | .Sh ERRORS | |
653ba8b6 KM |
48 | .Fn Listen |
49 | will fail if: | |
931b8415 CL |
50 | .Bl -tag -width [EOPNOTSUPP] |
51 | .It Bq Er EBADF | |
52 | The argument | |
53 | .Fa s | |
54 | is not a valid descriptor. | |
55 | .It Bq Er ENOTSOCK | |
56 | The argument | |
57 | .Fa s | |
58 | is not a socket. | |
59 | .It Bq Er EOPNOTSUPP | |
60 | The 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 | 68 | The |
931b8415 | 69 | .Fa backlog |
cf65baf0 | 70 | is currently limited (silently) to 5. |
931b8415 CL |
71 | .Sh HISTORY |
72 | The | |
73 | .Nm | |
74 | function call appeared in | |
75 | .Bx 4.2 . |