[Van-pm] Question about handling multiple clients

Jesse Sherlock jessesherlock at gmail.com
Fri Mar 31 10:18:06 PST 2006


If you like the API for threads, have a look at the forks libraries in
cpan, they look like perl threads (you may consider this good or bad)
but use fork. Threads are definitely not production ready in perl.

cheers,

Jesse

On 3/31/06, Kevin Scaldeferri <kevin at scaldeferri.com> wrote:
>
> On Mar 31, 2006, at 9:02 AM, Heng Ha wrote:
>
> > Hello everyone,
> >
> >    I am coding a daemon which should handle multiple
> > clients.
> >
> >    I referenced the pre-forking server code in Perl
> > cookbook that pre-forks several child processes and
> > each of them handle multiple requests.
> >
> >    The problem I got now is in the code the counter
> > calculates the number of incoming requests never
> > increments.
>
> The problem is that accept() will almost always return a true value, so
> that while loop never exits.  You don't have a timeout, so the only
> reason it should ever fail is if the local socket is closed for some
> reason or something borks the networking.  Otherwise, it just blocks
> until a connection comes in.
>
> To get the effect you want, you should combine the outer two loops or
> just get rid of the accept loops and do
>
>    $client = $server->accept() or last;
>
> which is actually what my copy of the cookbook has in this example.
>
>
>
> >
> >    The code is the following and can any one give me a
> > hand ? also, if possible, anyone has experience with
> > thread programming in perl, is that production ready ?
>
> Don't do it.
>
> If you need thread-like parallelism, POE is a much better idea.
>
> >
> >           # handle connections until we've reached
> > $MAX_CLIENTS_PER_CHILD
> >           for ($i=0; $i < $MAX_CLIENTS_PER_CHILD;
> > $i++)      {
> >              while ( $client = $server->accept( ) )
> >                   {
> >                     while ( <$client> )
> >                       {
> >                        #do something like print
> > $client....
> >
> >                       }
> >                        $client->shutdown(SHUT_RDWR);
> >                   }
> >               # do something with the connection
> >           }
> >
>
>
>
> -kevin
>
> _______________________________________________
> Vancouver-pm mailing list
> Vancouver-pm at pm.org
> http://mail.pm.org/mailman/listinfo/vancouver-pm
>


More information about the Vancouver-pm mailing list