delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/02/14/06:38:00

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 14 Feb 2003 12:37:49 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Socket problem after fork()
Message-ID: <20030214113749.GE31632@cygbert.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <F58BHr5mzoy2n8UziQN000246d8 AT hotmail DOT com>
Mime-Version: 1.0
In-Reply-To: <F58BHr5mzoy2n8UziQN000246d8@hotmail.com>
User-Agent: Mutt/1.4i

On Fri, Feb 14, 2003 at 10:33:23AM +0000, Henry Richard wrote:
> This time I upgrade my cygwin version to 1.3.20 and using gcc 3.2. The 
> program I submit last time does work in this new environment. How ever, I 
> have found that fork() can't be executed twice before closing the socket, 
> otherwise the telnet client will be blocked unless giving it a ^].
> 
> I think this problem is also caused by Winsock2 in Windows 2000 system, 
> according to Microsoft KB.
> [...]

I did play with sockets a lot to get it working almost as on POSIX
systems.  Actually I have no way around the described problem so far
as long as the application isn't changed.

However, the change is simple and useful, just add a shutdown() call
prior to the child's close():

>              loop=2;/* if loop is greater than 1, socket won't be closed 
> */
>              for (i = 0; i < loop; i++) {
>                      pid = fork();
>                      if (pid > 0) {
>                              close(accefd);
>                              return 0;
>                      }
>              }

               shutdown (accefd, SHUT_RDWR);

>              close(accefd);
>              sleep(100000);
>        }
> }

This helps.

Corinna

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

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019