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.
.\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
.\" All rights reserved.
.\"
.\" 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 1998 by Andi Kleen
.\" 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
listen \- listen for connections on a socket
.SH SYNOPSIS
@ -50,30 +52,31 @@ listen \- listen for connections on a socket
.BI "int listen(int " sockfd ", int " backlog );
.fi
.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 ()
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
or
.BR SOCK_SEQPACKET .
.PP
The
.I backlog
parameter defines the maximum length the queue of pending connections may
grow to.
If a connection request arrives with the queue full the client
argument defines the maximum length
to which the queue of pending connections for
.I sockd
may grow.
If a connection request arrives when the queue is full, the client
may receive an error with an indication of
.B ECONNREFUSED
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"
On success, zero is returned.
On error, \-1 is returned, and
@ -104,6 +107,26 @@ The
.BR listen ()
function call first appeared in 4.2BSD.
.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
.IR <sys/types.h> ,
and this header file is not required on Linux.