From 1e48734a0753896bb7ab8ccd1452c8bca816e787 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Thu, 27 Dec 2007 15:06:07 +0000 Subject: [PATCH] Rewrote various parts. --- man2/listen.2 | 55 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/man2/listen.2 b/man2/listen.2 index 33367b202..3874b0261 100644 --- a/man2/listen.2 +++ b/man2/listen.2 @@ -1,4 +1,5 @@ .\" Copyright (c) 1983, 1991 The Regents of the University of California. +.\" and Copyright (C) 2007, Michael Kerrisk .\" 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 .\" Modified 1998 by Andi Kleen .\" Modified 11 May 2001 by Sam Varshavchik +.\" .\" -.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 , and this header file is not required on Linux.