Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jul 2013 22:13:14 -0700
From:      Adrian Chadd <adrian@freebsd.org>
To:        "Ronald F. Guilmette" <rfg@tristatelogic.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: bin/176713: [patch] nc(1) closes network socket too soon
Message-ID:  <CAJ-Vmo=OcMkqeo4AA9MdZwbhabu0uQV%2BEc_1qKt4AeLeWN3gqA@mail.gmail.com>
In-Reply-To: <11109.1374623313@server1.tristatelogic.com>
References:  <CAJ-Vmonk-8v9ej0w4qycNNBkieOeE9dL3BTVp6VqipxKH2jSUA@mail.gmail.com> <11109.1374623313@server1.tristatelogic.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

Well, I've done this before. More than once. I'm glad that you've
stuck through helping me understand what nc is doing; I'm
unfortunately busy doing other things

What you end up doing is:

* tracking the state of the two sockets, both for read EOF and write EOF;
* whenever you get an EOF from one of the above four conditions, you
see whether you can still make progress. If so, you don't close the
socket - you just stop registering for that event. (Eg, if you see
read EOF on a socket, stop registering for read)
* if you see that both sides are read EOF'ed, then you can't possibly
make any more progress, right?
* .. no, you also have to THEN ensure that all the data you have
queued is written, OR that you hit write EOF (and thus can't make any
more progress anyway)

_then_ you shut things down.

Anyway. Leave it with me. Bug me if I don't commit either your fix, or
rearchitect it to do what I said above (and then test it, obviously :)


-adrian



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmo=OcMkqeo4AA9MdZwbhabu0uQV%2BEc_1qKt4AeLeWN3gqA>