Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Date: Mon, 16 Jul 2001 21:54:05 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: data in socketpair() channel lost if writer closes or exits without shutting down Message-ID: <20010716215405.F25442@cygbert.vinschen.de> Mail-Followup-To: cygwin AT cygwin DOT com References: <20010713181435 DOT 3695 DOT qmail AT lizard DOT curl DOT com> <20010713202146 DOT B11377 AT redhat DOT com> <20010716025220 DOT 23701 DOT qmail AT lizard DOT curl DOT com> <20010716095258 DOT P25442 AT cygbert DOT vinschen DOT de> <20010716180010 DOT 2309 DOT qmail AT lizard DOT curl DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010716180010.2309.qmail@lizard.curl.com>; from jik@curl.com on Mon, Jul 16, 2001 at 02:00:10PM -0400 On Mon, Jul 16, 2001 at 02:00:10PM -0400, Jonathan Kamens wrote: > The reason why things are different if the process exits is because > Winsock runs in user space. Windows can't leave something around > finishing up with data transmission after the process exits. On Unix, > on the other hand, sockets are handled in the kernel, and the kernel > will happily maintain that state and finish transmitting the data even > after the process which sent it is gone. AFAICS, that's the most important observation. I never thought about that. > Perhaps as a compromise we could set SO_LINGER on all new sockets with > a short timeout, say a few seconds, to give data time to flush. No, that's incorrect. Excerpt from W. Richard Stevens, "UNIX Network Programming Vol. 1, Network APIs: Sockets and XTI", 2nd Edition, p. 187: If l_onoff is nonzero and l_linger is 0, TCP aborts the connection when it is closed [...]. That is, TCP discards any data still remaining [...]. This avoids TCP's TIME_WAIT state, but in doing so leaves open the possibility of another incarnation of this connection being created within 2MSL seconds and having old duplicate segments from the just terminated connection being incorrectly delivered to the new incarnation [...]. > Or, slightly more complex but slightly more correct, keep track of > whether or not a socket was at some point shared between multiple > processes (either as a result of a fork or as a result of sending a > file descriptor between processes (does Cygwin support that?)). When > a socket is first shared, we can set SO_LINGER as I described above. > Then, when a socket is closed, check if it was ever shared and call > shutdown if it wasn't. Since Cygwin has currently no "device layer" (though planned for the future) we have no sharing of data between duplicated and inherited file descriptors, unfortunately. > > I just have that page "Graceful Shutdown, Linger Options, and > > Socket Closure" inside of MSDN, that's all. > > Amusingly enough, the link to that page on the "closesocket" page is > invalid. http://msdn.microsoft.com/library/en-us/winsock/hh/winsock/ovrvw3_3she.asp -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:cygwin AT cygwin DOT com Red Hat, Inc. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/