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: Tue, 9 Jan 2001 23:41:13 +0100 From: Corinna Vinschen To: cygwin Subject: Re: Winsock Bug Workaround - closing windows sockets Message-ID: <20010109234113.I4141@cobold.vinschen.de> Mail-Followup-To: cygwin References: <001801c07b31$d72a4720$904bb4ca AT private> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <001801c07b31$d72a4720$904bb4ca@private>; from david@rebirthing.co.nz on Wed, Jan 10, 2001 at 10:19:14AM -0800 On Wed, Jan 10, 2001 at 10:19:14AM -0800, David McNab wrote: > #ifdef __CYGWIN__ > int client_sock_flags; > struct linger lingeropt; > > /* flush out the client socket - set it to blocking, then write to it */ > client_sock_flags=fcntl(client,F_GETFL,0); > if(client_sock_flags!=-1) > /* enable blocking */ > fcntl(client,F_SETFL,client_sock_flags & ~O_NONBLOCK); > > /* sent it a byte - guaranteed to block - ensure delivery of prior data */ > /* yeah - this is a bit paranoid - try without this at first */ > /* write(client, "\n", 1); */ > > /* this is the guts of the workaround for Winsock close bug */ > shutdown(client, 1); > > /* enable lingering */ > lingeropt.l_onoff = 1; > lingeropt.l_linger = 15; > setsockopt(client, SOL_SOCKET, SO_LINGER, &lingeropt, sizeof(lingeropt)); > #endif > > /* Winsock bug averted - now we're safe to close the socket */ > close(client); Weeks ago I tried to implement something similar in fhandler_socket::close() itself to get rid of that problem but without luck. This is a good solution for applications but it's not generalizable, unfortunately. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:cygwin AT cygwin DOT com Red Hat, Inc. -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple