xref: /netbsd/lib/libc/sys/listen.2 (revision 64ebeb5c)
1*64ebeb5cSwiz.\"	$NetBSD: listen.2,v 1.16 2004/05/13 10:20:58 wiz Exp $
24eab61bdScgd.\"
34eab61bdScgd.\" Copyright (c) 1983, 1991, 1993
44eab61bdScgd.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" Redistribution and use in source and binary forms, with or without
761f28255Scgd.\" modification, are permitted provided that the following conditions
861f28255Scgd.\" are met:
961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1061f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1261f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1361f28255Scgd.\"    documentation and/or other materials provided with the distribution.
14eb7c1594Sagc.\" 3. Neither the name of the University nor the names of its contributors
1561f28255Scgd.\"    may be used to endorse or promote products derived from this software
1661f28255Scgd.\"    without specific prior written permission.
1761f28255Scgd.\"
1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2161f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2861f28255Scgd.\" SUCH DAMAGE.
2961f28255Scgd.\"
304eab61bdScgd.\"     @(#)listen.2	8.2 (Berkeley) 12/11/93
3161f28255Scgd.\"
324eab61bdScgd.Dd December 11, 1993
3361f28255Scgd.Dt LISTEN 2
3438c96853Sgarbled.Os
3561f28255Scgd.Sh NAME
3661f28255Scgd.Nm listen
3761f28255Scgd.Nd listen for connections on a socket
3815be242bSkleink.Sh LIBRARY
3915be242bSkleink.Lb libc
4061f28255Scgd.Sh SYNOPSIS
41472351e1Swiz.In sys/socket.h
4261f28255Scgd.Ft int
4361f28255Scgd.Fn listen "int s" "int backlog"
4461f28255Scgd.Sh DESCRIPTION
4561f28255ScgdTo accept connections, a socket
4661f28255Scgdis first created with
4761f28255Scgd.Xr socket 2 ,
4861f28255Scgda willingness to accept incoming connections and
4961f28255Scgda queue limit for incoming connections are specified with
5061f28255Scgd.Fn listen ,
5161f28255Scgdand then the connections are
5261f28255Scgdaccepted with
5361f28255Scgd.Xr accept 2 .
5461f28255ScgdThe
5561f28255Scgd.Fn listen
5661f28255Scgdcall applies only to sockets of type
5761f28255Scgd.Dv SOCK_STREAM
5861f28255Scgdor
5961f28255Scgd.Dv SOCK_SEQPACKET .
6061f28255Scgd.Pp
6161f28255ScgdThe
6261f28255Scgd.Fa backlog
6361f28255Scgdparameter defines the maximum length the queue of
6461f28255Scgdpending connections may grow to.
6561f28255ScgdIf a connection
6661f28255Scgdrequest arrives with the queue full the client may
6761f28255Scgdreceive an error with an indication of
6861f28255Scgd.Er ECONNREFUSED ,
6961f28255Scgdor, if the underlying protocol supports retransmission,
7061f28255Scgdthe request may be ignored so that retries may succeed.
7161f28255Scgd.Sh RETURN VALUES
72*64ebeb5cSwizA 0 return value indicates success; \-1 indicates an error.
7361f28255Scgd.Sh ERRORS
74ce83c69eSlukem.Fn listen
759c4ad8fbSjtcwill fail if:
76250b6aa0Sjtc.Bl -tag -width Er
7761f28255Scgd.It Bq Er EBADF
7861f28255ScgdThe argument
7961f28255Scgd.Fa s
8061f28255Scgdis not a valid descriptor.
8161f28255Scgd.It Bq Er ENOTSOCK
8261f28255ScgdThe argument
8361f28255Scgd.Fa s
8461f28255Scgdis not a socket.
8561f28255Scgd.It Bq Er EOPNOTSUPP
8661f28255ScgdThe socket is not of a type that supports the operation
8761f28255Scgd.Fn listen .
8861f28255Scgd.El
8961f28255Scgd.Sh SEE ALSO
9061f28255Scgd.Xr accept 2 ,
9161f28255Scgd.Xr connect 2 ,
9261f28255Scgd.Xr socket 2
9361f28255Scgd.Sh HISTORY
9461f28255ScgdThe
956e9ac180Sjtc.Fn listen
9661f28255Scgdfunction call appeared in
9761f28255Scgd.Bx 4.2 .
9853d84b5cSwiz.Sh BUGS
9953d84b5cSwizThe
10053d84b5cSwiz.Fa backlog
10153d84b5cSwizis currently limited (silently) to 128.
102