From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bakul Shah Content-Type: multipart/alternative; boundary=Apple-Mail-BEECE8EC-96A8-470B-846A-15809CB7A6B4 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) Date: Fri, 3 Feb 2017 22:29:16 -0800 Message-Id: References: In-Reply-To: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] adding TCP half-duplex close Topicbox-Message-UUID: b34cc8f0-ead9-11e9-9d60-3106f5b1d025 --Apple-Mail-BEECE8EC-96A8-470B-846A-15809CB7A6B4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable For the shut_rd case, I think a cleaner impl is to send RST *only* if there i= s pending data (received but not read by the user) or new data is received a= fter the read end is closed. At the moment I don't recall what BSD does but y= ou don't have to allow draining once the read end is closed. Just drain and R= ST! Any user reads should fail. I recall having to deal with this in the past while working on a packet leve= l network proxy. No access to that code now so the above is from memory. Sent from my iPad > On Feb 3, 2017, at 5:56 PM, Skip Tavakkolian w= rote: >=20 > Has anyone looked into implementing this? Can anyone comment on the detai= ls? >=20 > For the curious, this is described here: https://tools.ietf.org/html/rfc11= 22#page-87 > Go net package (https://github.com/golang/go/issues/17906). >=20 > As I understand it, one would only worry about 'shutdown' if the connectio= n is in 'Established' state. It is not clear to me what the state should tra= nsition to when the read-end is closed (i.e. shut_rd). Also, there doesn't n= ot seem to be consistency between different implementations (Windows,Linux, *= BSD) on what should happen to what's already in the read queue; should it be= allowed to drain to the reader or discarded immediately? >=20 > Shutting down the write-end (i.e. 'shut_wr'), should send FIN, and transit= ion to Finwait1. >=20 > I think the correct mechanics to handle this would be to add two new messa= ges in tcpctl (/sys/src/9/ip/tcp.c). Then, roughly something like this: >=20 > case 'shut_rd' :=20 > if (Etablished) { > qhangup(rq); > send(RST); // Windows does this and RFC1122 seems to recommend it. Linu= x does not. > tcb->rcv.blocked =3D 1; // all that's needed? > tcb->rcv.wnd =3D 0; > tcpsetstate(????) // not sure what it should be or should stay Establis= hed? > } >=20 > case 'shut_wr': > if (Established) { > qhangup(wq); > send(FIN) > tcpsetstate(Finwait_1) > } >=20 >=20 --Apple-Mail-BEECE8EC-96A8-470B-846A-15809CB7A6B4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
For the shut_rd case, I think a cleane= r impl is to send RST *only* if there is pending data (received but not read= by the user) or new data is received after the read end is closed. At the m= oment I don't recall what BSD does but you don't have to allow draining once= the read end is closed. Just drain and RST! Any user reads should fail.

I recall having to deal with this in the past while wo= rking on a packet level network proxy. No access to that code now so the above is f= rom memory.



Sent from my iPad
On Feb 3, 2017= , at 5:56 PM, Skip Tavakkolian <skip.tavakkolian@gmail.com> wrote:

=
= --Apple-Mail-BEECE8EC-96A8-470B-846A-15809CB7A6B4--