Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: TCP Server hangs with multiple client connections

by Khen1950fx (Canon)
on Aug 02, 2012 at 19:45 UTC ( #985097=note: print w/ replies, xml ) Need Help??


in reply to TCP Server hangs with multiple client connections

I looked at your server socket. There's a problem with IO::Select's can_read. If there's no timeout given, or if it contains a registered handler, can_read will block. Here's how I would handle the socket:

#!/usr/bin/perl select(STDERR); $| = 1; select(STDOUT); $| = 1; use autodie; use strictures 1; use IO::Socket; use IO::Select; use Log::Log4perl; my $sock = new IO::Socket::INET( LocalAddr => 'www.example.com', LocalPort => 9000, Listen => 128, Reuse => 1, Blocking => 0, Proto => 'tcp', ); our $selSock = new IO::Select($sock); while( my(@ready) = $selSock->can_read(10) ) { use strict qw/refs/; use warnings FATAL => 'syntax'; foreach $_ (@ready) { if ($_ == $sock) { my $logger; my $clientPool; $logger->info("Base socket is " . $sock); $logger->info("Adding new socket"); my $newSock = $sock->accept or die; $logger->info("Added new socket " . $newSock); $selSock->add($newSock); my $fd = $selSock->fileno($newSock); my $address = inet_ntoa($newSock->peeraddr); my @values = ($fd, $address); if ($clientPool->queueJob( queueValues => \@values)) { $logger->error( "Failed to queue client connection" ); my $trash = <$newSock>; $trash->send($newSock, "** ENQUEUE_FAILED **", 0); $trash->send($newSock, "** ZERO_BYTES_LEFT **", 0); $selSock->remove($trash); $newSock = undef; sleep 1; exit; } } } }


Comment on Re: TCP Server hangs with multiple client connections
Download Code
Re^2: TCP Server hangs with multiple client connections
by rmahin (Beadle) on Aug 02, 2012 at 20:53 UTC
    Tried what you suggested, changed it a little though to
    while(1) { use strict qw/refs/; use warnings FATAL => 'syntax'; my @ready = $selSock->can_read(10); unless (@ready) {next};
    so that it wouldn't die if no clients connected. But anyway, and had no effect that I could see. Thanks for the suggestion though!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-12-19 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (83 votes), past polls