This is the mail archive of the cygwin-patches@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: Workaround patch for MS CLOSE_WAIT bug


On Sun, Apr 14, 2002 at 03:29:44PM -0400, Pierre A. Humblet wrote:
> Fixing the application
> **********************
> To keep sock open in the parent, the ported application 
> structure can be changed to:
> 
> int oldsocks[2^32];  /* I'll be smarter */
> sock = socket()     (1)
> bind(sock)
> listen(sock)
> while (1) {
>  select()
>  newsock = accept(sock)
>  pid = fork()
>  if (pid == 0) { 
>     close(sock)     (2)
>     child works 
>  }
>  if (pid > 0) {
>     oldsocks[pid] = newsock
>                  <= (3)
>  }
> }
> sigchild_handler()
> { 
>   pid = waitpid()
>   close(oldsocks[pid]) (4)
> }

Your patch looks good.  What I didn't quite get is, how the above
code now looks like (ideally) when using the new FD_SETCF functionality.
Could you write a short example?  If inetd (what about sshd?) could
benefit, I'd like to see how to do it.  Btw., the sources are in the
inetutils-1.3.2-17-src.tar.bz2 file, obviously, which you can get
by using setup.exe.

> Problems with duplicate LISTEN have also been reported
> by me and others
> http://sources.redhat.com/ml/cygwin/2002-01/msg01579.html
> http://sources.redhat.com/ml/cygwin/2002-04/msg00515.html
> No progress there, it's mind boggling. My problem occurs 
> only when the server re-execs itself while a child is 
> running. "close on fork" doesn't seem to help.

That's a pity.  I have no idea what the cause for that is.  As Chris
noted, there's a listening socket created in start_thread_socket()
in select.cc but from all I can see it's closed correctly when it's
not used anymore.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.


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