This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Long duration of close(socket) and signal problem


> 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.
>
An strace of fakeweb with a patchec cygwin.dll which prints
an additional timestamp on entering fhandler_socket::close()
shows that the time is consumed in the
fhandler_socket::close().
<snip>
  240 10050859 [main] fakeweb 2272 _close: close (4)
  110 10050969 [main] fakeweb 2272 fhandler_socket::close:
fhandler_socket::close()
329915 10380884 [main] fakeweb 2272 fhandler_socket::close:
0 = fhandler_socket::close()
<snip>

I assume this happens in the loop with the closesocket()
call. Has anyone additional comments ?

 fhandler_socket::close ()
{
  debug_printf ("fhandler_socket::close()");
  int res = 0;
  sigframe thisframe (mainthread);

  /* 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);

  while ((res = closesocket (get_socket ()))
	 && WSAGetLastError () == WSAEWOULDBLOCK)
    continue;
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  if (res)
    {
      set_winsock_errno ();
      res = -1;
    }

  close_secret_event ();

  debug_printf ("%d = fhandler_socket::close()", res);
  return res;
}



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]