From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 24 23:43:43 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0B07E476; Wed, 24 Jul 2013 23:43:43 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id DDB1021D4; Wed, 24 Jul 2013 23:43:41 +0000 (UTC) Received: from segfault-nmh-helo.tristatelogic.com (localhost [127.0.0.1]) by segfault.tristatelogic.com (Postfix) with ESMTP id 80D213B73C; Wed, 24 Jul 2013 16:43:37 -0700 (PDT) From: "Ronald F. Guilmette" To: Adrian Chadd Subject: Re: bin/176713: [patch] nc(1) closes network socket too soon In-Reply-To: Date: Wed, 24 Jul 2013 16:43:37 -0700 Message-ID: <59915.1374709417@server1.tristatelogic.com> Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jul 2013 23:43:43 -0000 In message , you wrote: >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 :) Thank you. Please consider yourself bugged. (1/2 :-)