Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Multithreaded Socket Listener

by Anonymous Monk
on Nov 14, 2012 at 22:13 UTC ( #1003895=note: print w/ replies, xml ) Need Help??


in reply to Multithreaded Socket Listener

I know it's a big piece of code and looks ugly here. Sorry for this. If somebody has a hint for me - I would be very thankful :O)

It looks ugly anywhere :) seriously, subroutines should (for the most part) take arguments, not operate on global variables

You need more subroutines, there is way too much code outside of subroutines.

Instead of # build a list of files to check you need  my @resultfiles = files_to_check( $properties );

Your code contains exit 18 times -- way too many,

Your loop should be short, like

while( $client = $server->accept() ) { if( my $pid = fork() ){ $logger->debug( "this is parent process closing client now" ); $client->close(); $logger->debug( "parent closed client" ); } else { KidStuff( $client , $logger, $pid, ... ); } }

This might interest you A suicidal parent OR death of a forking server

That's about all I got, except, you say you're using a browser -- then you might as well use write a plain old "CGI" PSGI, say with cgi-app / mojo / dancer / catalyst... and make it multithreaded with Perlbal or any other applicable server (feature of PSGI), instead of reinventing this particular wheel

Also, see Proc::Background :)


Comment on Re: Multithreaded Socket Listener
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-11-22 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (125 votes), past polls