Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Ralf Habacker" To: "cygwin" Subject: RE: Long duration of close(socket) and signal problem Date: Wed, 20 Mar 2002 15:00:53 +0100 Message-ID: <00f001c1d017$a67c1720$276107d5@BRAMSCHE> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00F1_01C1D020.08407F20" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 In-Reply-To: <000901c1c45a$9d8563b0$651c440a@BRAMSCHE> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal ------=_NextPart_000_00F1_01C1D020.08407F20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > > To my great surprise, the close(socket) operation > > took EXTREMELY long. It > > took 0.11 second (CPU usage was low), while this > > operation under MinGW 1.1 > > on the same machine took only 0.00019 second. On > > another Linux machine, > > close took 0.000043 second. > > A solution may be in calling shutdown() if not called before by the application before calling closesocket(). I have tried like this with success. -- without shutdown() ---- accept: 0.000000 recv: 0.011112 send: 0.000069 shutdown: 0.000000 close: 0.328966 -- with shutdown(s,SHUT_WR) ---- accept: 0.000000 recv: 0.012169 send: 0.000089 shutdown: 0.000112 close: 0.000105 Question: Does adding shutdown make the following code obsolate ? (I have assumed so in my appended patch) fhandler_socket::close() ---old--- /* HACK to allow a graceful shutdown even if shutdown() hasn't been called by the application. Note that this isn't the ultimate solution but it helps in many cases. */ struct linger linger; linger.l_onoff = 1; linger.l_linger = 240; /* seconds. default 2MSL value according to MSDN. */ setsockopt (get_socket (), SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof linger); --new---- if (!saw_shutdown_read () && !saw_shutdown_write ()) shutdown(get_socket (),SD_BOTH); --------- Any comments to this ? What about win95 and other os. Could there be any problems ? Regards Ralf ------=_NextPart_000_00F1_01C1D020.08407F20 Content-Type: application/octet-stream; name="shutdown.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="shutdown.patch" Index: fhandler_socket.cc=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/winsup/cygwin/fhandler_socket.cc,v=0A= retrieving revision 1.41=0A= diff -u -p -r1.41 fhandler_socket.cc=0A= --- fhandler_socket.cc 2002/03/05 18:02:53 1.41=0A= +++ fhandler_socket.cc 2002/03/20 11:30:36=0A= @@ -343,14 +343,8 @@ fhandler_socket::close ()=0A= int res =3D 0;=0A= sigframe thisframe (mainthread);=0A= =0A= - /* HACK to allow a graceful shutdown even if shutdown() hasn't been=0A= - called by the application. Note that this isn't the ultimate=0A= - solution but it helps in many cases. */=0A= - struct linger linger;=0A= - linger.l_onoff =3D 1;=0A= - linger.l_linger =3D 240; /* seconds. default 2MSL value according to = MSDN. */=0A= - setsockopt (get_socket (), SOL_SOCKET, SO_LINGER,=0A= - (const char *)&linger, sizeof linger);=0A= + if (!saw_shutdown_read () && !saw_shutdown_write ())=0A= + shutdown(get_socket (),SD_BOTH); =0A= =0A= while ((res =3D closesocket (get_socket ())) !=3D 0)=0A= {=0A= ------=_NextPart_000_00F1_01C1D020.08407F20 Content-Type: application/octet-stream; name="shutdown.ChangeLog" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="shutdown.ChangeLog" 2002-03-19 Ralf Habacker * fhandler_socket.cc (fhandler_socket::close): Added call to shutdown() in cases not called before to avoid delays. ------=_NextPart_000_00F1_01C1D020.08407F20 Content-Type: text/plain; charset=us-ascii -- 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/ ------=_NextPart_000_00F1_01C1D020.08407F20--