Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003895]
[Discipulus]: good morning nuns and monks!

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2018-06-25 07:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.