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.1 (Berkeley) 06/04/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 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 67The 68.Fa backlog 69is currently limited (silently) to 5. 70.Sh HISTORY 71The 72.Nm 73function call appeared in 74.Bx 4.2 . 75