Well, I'd guess you'd be able to pretty much copy the code you use for processing directly into a Net::Server interface without a lot of changes, since you don't really seem to be using the threads for anything but parallel workers.
Something along the lines of this, not tested, of course.
sub process_request {
my $self = shift;
my $fh = $self->{server}->{client};
my $select = IO::Select->new();
$select->add($fh);
my $last = 1;
while ($last) {
my $subroutineCall;
my $command;
my $completeLine = "";
# check if anything is ready to be received from client
my @ready = $select->can_read(.1);
next unless (@ready);
# loop while receiving from the client untill a full msg has b
+een received as identified by our flags
while ( defined( my $line = <$fh> ) ) {
if ( $line =~ /\*\*\* CLOSE_CONNECTION_CLIENT \*\*\*\n$/ )
+ {
$logger->info("Client closed connection to the server"
+);
$last = 0;
$selSock->remove($fh);
shutdown( $fh, 2 );
close $fh;
last;
}
$completeLine .= $line;
if ( $completeLine
=~ /(.+) \*\*\* COMMAND_INPUT \*\*\* (.+) \*\*\* COMMA
+ND_INPUT_END \*\*\*\n$/is
)
{
$subroutineCall = $1;
$command = $2;
$logger->info( "Processing message \"" . $command . "\
+"" );
last;
}
}
if ($last) {
#checking if the subroutine call is defined, if not, it kills that cli
+ent connection (for cases of closing out of a client window and it se
+nding the empty string )
if ( defined($subroutineCall) )
{
$logger->debug("Calling subroutine '${subroutineCa
+ll}'");
my ($string) = executeCommand(
subCall => $subroutineCall,
command => $command
);
send( $fh, "$string\n*** ZERO_BYTES_LEFT ***", 0 )
+;
}
else {
$logger->info(
"Undefined subroutine passed, closing client c
+onnection."
);
$last = 0;
$selSock->remove($fh);
shutdown( $fh, 2 );
close $fh;
last;
}
}
}
}
- Ant
- Some of my
best work - (1 2 3)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|