This is the mail archive of the 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
> 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 but from all I can see it's closed correctly when it's
not used anymore.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                      
Red Hat, Inc.

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