Received: from PACIFIC-CARRIER-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA20182; Wed, 13 Dec 95 17:08:31 EST
Received: from halloran-eldar.lcs.mit.edu by MIT.EDU with SMTP
	id AA11330; Wed, 13 Dec 95 17:08:35 EST
Received: from freefall.FreeBSD.ORG by halloran-eldar.lcs.mit.edu; (5.65/1.1.8.2/19Aug95-0530PM)
	id AA11636; Wed, 13 Dec 1995 17:06:33 -0500
Received: from localhost (daemon@localhost)
          by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id NAA25116
          Wed, 13 Dec 1995 13:08:25 -0800 (PST)
Received: (from root@localhost)
          by freefall.freebsd.org (8.7.3/8.7.3) id NAA24910
          for hackers-outgoing; Wed, 13 Dec 1995 13:06:44 -0800 (PST)
Received: from bubba.tribe.com ([205.184.207.7])
          by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id NAA24896
          for <freebsd-hackers@freebsd.org>; Wed, 13 Dec 1995 13:06:36 -0800 (PST)
Received: (from archie@localhost) by bubba.tribe.com (8.6.12/8.6.12) id NAA26701 for freebsd-hackers@freebsd.org; Wed, 13 Dec 1995 13:05:32 -0800
From: Archie Cobbs <archie@tribe.com>
Message-Id: <199512132105.NAA26701@bubba.tribe.com>
Subject: listen(2) semantics
To: freebsd-hackers@freebsd.org
Date: Wed, 13 Dec 1995 13:05:32 -0800 (PST)
X-Mailer: ELM [version 2.4 PL24]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Sender: owner-hackers@freebsd.org
Precedence: bulk


I'm confused about the "backlog" parameter of the listen(2)
system call... I have a program which calls "listen(sock, 0)",
specifying a maximum pending connection queue length of zero.

Now here's what the man page says:

  The 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 may receive an error with an indication
  of ECONNREFUSED, or, if the underlying protocol supports retransmission,
  the request may be ignored so that retries may succeed.

However, the observed behavior is this: the first connection succeeds
and data is exchanged, the second connection "succeeds" but no data
is read by the server (until the first connection exits), and the third
connection fails via mode 2 described above.

My question is how come the second connection doesn't fail via mode 2?
Why does it say "connected to ..." when it's not really connected
and the queue of pending connections supposedly has length zero? It
seems like it ought to fail if someone is already connected.

I.E, which of the following is the case and why :-)

 1 I'm misinterpreting the man page
 2 The man page is inaccurate
 3 The implementation of listen(2) is wrong

Example:

  $ telnet localhost 6006
  Trying 127.0.0.1...
  Connected to localhost.tribe.com.
  Escape character is '^]'.

  ^]
  telnet> ^Z
  Suspended
  $ telnet localhost 6006
  Trying 127.0.0.1...
  Connected to localhost.tribe.com.
  Escape character is '^]'.

  ^]
  telnet> ^Z
  Suspended
  $ telnet localhost 6006
  Trying 127.0.0.1...            <-- hangs, failing via mode 2
  ^C

Thanks,
-Archie

_______________________________________________________________________________
Archie L. Cobbs, archie@tribe.com  *  Tribe Computer Works http://www.tribe.com
