From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 24 05:13:17 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 000F786F for ; Wed, 24 Jul 2013 05:13:16 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-we0-x22f.google.com (mail-we0-x22f.google.com [IPv6:2a00:1450:400c:c03::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9033A29B3 for ; Wed, 24 Jul 2013 05:13:16 +0000 (UTC) Received: by mail-we0-f175.google.com with SMTP id q58so744907wes.34 for ; Tue, 23 Jul 2013 22:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=uwkCR3dVDaEiopoogRxy5d75npGjK3Jk7f0pDFSDxfw=; b=GfjTtFEkxYXmsMmDjM97VHtfICO+eSKZjzm32xKfy5NOEE9fgKSnv39B5Aqbc1sQJw dJ1hOFUHvGs8Ejo5QM+LmWCkJ+F9wtRR9pdwhicmS04wpyBYi/ICXwTgi3z+r59hBzKN G/98pymf9N0YRpKzLL6qhvt1oDwgLPIv030hDT5t6UaqSeHjgrTmgvCfpeCYx6Gd3kRJ ID3JJ96I8qU7EZYxBulzrZkwYuMkPZjX+YIC2d2weHYtkdkUzjouXidV5LZE3Vt2TzBB mh9E+OY9M12iXdhvQ41oFJc2v21wfb9TB2GTACklD1Krd+9l8lPjJeOWnSh1nsJtbe0l Tr6g== MIME-Version: 1.0 X-Received: by 10.194.92.6 with SMTP id ci6mr1307532wjb.79.1374642794712; Tue, 23 Jul 2013 22:13:14 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.217.94.132 with HTTP; Tue, 23 Jul 2013 22:13:14 -0700 (PDT) In-Reply-To: <11109.1374623313@server1.tristatelogic.com> References: <11109.1374623313@server1.tristatelogic.com> Date: Tue, 23 Jul 2013 22:13:14 -0700 X-Google-Sender-Auth: n2eGnzwlc4ocgMYIE9fduIIK0SY Message-ID: Subject: Re: bin/176713: [patch] nc(1) closes network socket too soon From: Adrian Chadd To: "Ronald F. Guilmette" Content-Type: text/plain; charset=ISO-8859-1 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 05:13:17 -0000 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