Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Sat, 17 Sep 2005 13:01:40 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: socket troubles
Message-ID: <20050917110140.GS5555@calimero.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <4a03a72c050916125687025c1@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4a03a72c050916125687025c1@mail.gmail.com>
User-Agent: Mutt/1.4.2i

On Sep 16 21:56, znort wrote:
>   while(1)
>   {
>     errno=0;
> 
>     sock = accept(sd, NULL,NULL);
>     
>     if (errno==0)
>     {
>       rf = fork();
> 
>       /* father will still listener forever */
>       if (!rf)
>       {
>           fcntl(sock, F_SETFL, f & (~O_NONBLOCK) );
>   
>           shutdown(sd, SHUT_RDWR);
>           recv(sock, ok, 2048, 0);
>           
>           sprintf(ok, "01101996 123 444");
>           send(sock, ok, strlen(ok)+1, 0);
>           
>           /* no return from client just to "block" the child */
>           recv(sock, ok, 2048, 0);
>           
>           shutdown(sock, SHUT_RDWR);
> 
>           break;
>       }
>     }
>     else
>     {
>       printf("errno = %d", errno);
>     }
>   }

You're waisting resources, that's the problem.  Observe the handle
usage of your server process while running the client, and you'll
be surprised.

shutdown doesn't close the socket and consequentially doesn't remove
the socket from the system tables.  Use close instead of shutdown.
Also, if you never call wait or waitpid to reap child processes, you
end up with lots of zombie processes (the child processes you don't
see in task manager).

Next time, please convert your test application to compile under gcc,
not VC++.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

