Try replacing your handledata() sub with this:
sub handleData { my $tid = threads->tid(); my $fno = $Q->dequeue(); my $clientAddr = $Q->dequeue(); next if $fno eq 'STOP'; my ( $clientPort, $clientIp ) = sockaddr_in( $clientAddr ); my $ipStr = inet_ntoa( $clientIp ); open my $socket, '+<&=' . $fno or die $!; my $request = <$socket>; chomp $request; if ($request eq '<policy-file-request/>') { warn("($tid) : XML Policy file request from: $ipStr"); print $socket $content.$NULLBYTE; } else { warn("($tid) : Connection from: $ipStr"); print $socket "<data><ip>$ipStr</ip></data>".$NULLBYTE; } shutdown $socket, 2; close $socket; return 1; }
I don't anticipate that it will perform better than your non-threaded solution for teh reasons I stated above. Create a new thread to reply with a single line of code is never going to be quicker than replying inline, but it might just work well enough to allow you to see that for yourself.
For the application as you've posted, I am quite certain that you will not improve your performance using threads this way.
You'd almost certainly be better off using IO::Socket::INET and setting the Listener option to allow the tcpip stack to queue inbound requests.
In reply to Re^3: Trying to thread a daemon with threads and Thread::Queue
by BrowserUk
in thread Trying to thread a daemon with threads and Thread::Queue
by jasmineaura
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |