The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: torek@torek.net (Chris Torek)
Subject: [TUHS] Sockets and the true UNIX
Date: Fri, 22 Sep 2017 11:00:41 -0700	[thread overview]
Message-ID: <201709221800.v8MI0fSM069953@elf.torek.net> (raw)
In-Reply-To: Your message of "Fri, 22 Sep 2017 12:36:34 +0200." <14E85999-B179-48C7-A93F-63D942207525@planet.nl>

[I said]
>> This also knocks out the need for SO_REUSEADDR ...

>Under TCP/IP I'm not sure you can. The protocol specifies that you must
>wait for a certain period of time (120 sec, if memory serves my right)
>before reusing an address/port combo, so that all in-flight packets have
>disappeared from the network. Only if one is sure that this is not an
>issue one can use SO_REUSEADDR.

That's independent of this issue.  The problem is that when you
call bind(), the system does not know if you are doing it as
the first half of bind()/connect(), or as the first half of
bind()/listen( (followed by an accept() loop).

If you are going to do the latter, you are declaring that you want
to serve *new* SYN requests.  This is when you (currently) must set
SO_REUSEADDR, because bind() checks your local address against the
universe of all local/remote pairs.  But if the system knows that
your call (which, remember, isn't bind() anymore) is your
declaration of intent to be a server, the OS can just check
whether there's already someone declared as "the server".

If you intend to "serve" one specific foreign address (FTP):

   bind_and_connect(fd, local, remote);

the test is: "does <local,remote> specify a unique address"
(and possibly "does <local> match what we already suggested
to you and reserved for you).  If you intend to serve "*":

   bind_and_connect(fd, local, NULL);

the test is: "is there already a <local,*>".

In the server case any existing 2MSL timeouts are irrelevant;
what matters is whether you are competing with another server.

(Note that libc will probably have various convenience wrappers
atop the system call, kind of like libc has system() atop
fork/exec.  Most programs just want to create and bind_and_connect
a socket in one pass.)

Chris



  parent reply	other threads:[~2017-09-22 18:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1105.1506026200.3779.tuhs@minnie.tuhs.org>
2017-09-22 10:36 ` Paul Ruizendaal
2017-09-22 14:32   ` Clem Cole
2017-09-22 14:42     ` Chet Ramey
2017-09-22 14:47       ` Chet Ramey
2017-09-22 14:52         ` Lars Brinkhoff
2017-09-22 14:49       ` Larry McVoy
2017-09-22 14:57         ` Chet Ramey
2017-09-22 18:14           ` Chris Torek
2017-09-22 18:43             ` Clem Cole
2017-09-22 19:08             ` Chet Ramey
2017-09-22 20:57               ` Chris Torek
2017-09-24 18:04                 ` Chet Ramey
2017-09-22 18:00   ` Chris Torek [this message]
2017-09-25 17:57 Norman Wilson
2017-09-25 18:55 ` Clem Cole
  -- strict thread matches above, loose matches on Subject: below --
2017-09-21 16:01 Ian Zimmerman
2017-09-21 16:07 ` Chet Ramey
2017-09-21 16:10 ` Larry McVoy
2017-09-21 16:20   ` David Edmondson
2017-09-21 16:25   ` Clem Cole
2017-09-21 16:27     ` Larry McVoy
2017-09-21 18:26   ` Chet Ramey
2017-09-21 16:13 ` Jon Steinhart
2017-09-21 16:17   ` Larry McVoy
2017-09-21 20:36     ` Chris Torek
2017-09-21 18:56   ` Bakul Shah
2017-09-21 19:13     ` Steve Simon
2017-09-21 19:31       ` Bakul Shah
2017-09-21 20:15         ` ron minnich
2017-09-21 20:34           ` Clem Cole
2017-09-21 23:26   ` Dave Horsfall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201709221800.v8MI0fSM069953@elf.torek.net \
    --to=torek@torek.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).