delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/09/17/07:02:04

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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: Sat, 17 Sep 2005 13:01:40 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: socket troubles
Message-ID: <20050917110140.GS5555@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <4a03a72c050916125687025c1 AT mail DOT gmail DOT com>
Mime-Version: 1.0
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/

- Raw text -


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