Long duration of close(socket) and signal problem

Ralf Habacker Ralf.Habacker@freenet.de
Wed Mar 20 06:21:00 GMT 2002


> > 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: shutdown.patch
Type: application/octet-stream
Size: 973 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20020320/ad0a18e1/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shutdown.ChangeLog
Type: application/octet-stream
Size: 179 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20020320/ad0a18e1/attachment-0001.obj>
-------------- next part --------------
--
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/


More information about the Cygwin mailing list