This is the mail archive of the cygwin 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: socket troubles


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/


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