Rewrote various parts.

This commit is contained in:
Michael Kerrisk 2007-12-27 15:06:07 +00:00
parent 791ce3b986
commit 1e48734a07
1 changed files with 39 additions and 16 deletions

View File

@ -1,4 +1,5 @@
.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
.\" All rights reserved. .\" All rights reserved.
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
@ -37,8 +38,9 @@
.\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com> .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1998 by Andi Kleen .\" Modified 1998 by Andi Kleen
.\" Modified 11 May 2001 by Sam Varshavchik <mrsam@courier-mta.com> .\" Modified 11 May 2001 by Sam Varshavchik <mrsam@courier-mta.com>
.\"
.\" .\"
.TH LISTEN 2 1993-07-23 "Linux" "Linux Programmer's Manual" .TH LISTEN 2 2007-12-28 "Linux" "Linux Programmer's Manual"
.SH NAME .SH NAME
listen \- listen for connections on a socket listen \- listen for connections on a socket
.SH SYNOPSIS .SH SYNOPSIS
@ -50,30 +52,31 @@ listen \- listen for connections on a socket
.BI "int listen(int " sockfd ", int " backlog ); .BI "int listen(int " sockfd ", int " backlog );
.fi .fi
.SH DESCRIPTION .SH DESCRIPTION
To accept connections, a socket is first created with
.BR socket (2),
a willingness to accept incoming connections and a queue limit for incoming
connections are specified with
.BR listen (),
and then the connections are
accepted with
.BR accept (2).
The
.BR listen () .BR listen ()
call applies only to sockets of type marks the socket referred to by
.I sockfd
as a passive socket, that is, as a socket that will
be used to accept incoming connection requests using
.BR accept (2).
The
.I sockfd
argument is a file descriptor that refers to a socket of type
.B SOCK_STREAM .B SOCK_STREAM
or or
.BR SOCK_SEQPACKET . .BR SOCK_SEQPACKET .
.PP
The The
.I backlog .I backlog
parameter defines the maximum length the queue of pending connections may argument defines the maximum length
grow to. to which the queue of pending connections for
If a connection request arrives with the queue full the client .I sockd
may grow.
If a connection request arrives when the queue is full, the client
may receive an error with an indication of may receive an error with an indication of
.B ECONNREFUSED .B ECONNREFUSED
or, if the underlying protocol supports retransmission, the request may be or, if the underlying protocol supports retransmission, the request may be
ignored so that retries succeed. ignored so that a later reattempt at connection succeeds.
.SH "RETURN VALUE" .SH "RETURN VALUE"
On success, zero is returned. On success, zero is returned.
On error, \-1 is returned, and On error, \-1 is returned, and
@ -104,6 +107,26 @@ The
.BR listen () .BR listen ()
function call first appeared in 4.2BSD. function call first appeared in 4.2BSD.
.SH NOTES .SH NOTES
To accept connections, the following steps are performed:
.RS 4
.IP 1. 4
A socket is created with
.BR socket (2).
.IP 2.
The socket is bound to a local address using
.BR bind (2),
so that other sockets may be
.BR connect (2)ed
to it.
.IP 3.
A willingness to accept incoming connections and a queue limit for incoming
connections are specified with
.BR listen ().
.IP 4.
Connections are accepted with
.BR accept (2).
.RE
.PP
POSIX.1-2001 does not require the inclusion of POSIX.1-2001 does not require the inclusion of
.IR <sys/types.h> , .IR <sys/types.h> ,
and this header file is not required on Linux. and this header file is not required on Linux.