Hello,
I have a problem using a threaded TCP-server. Clients connect to
send a short message. This message is then processed. This processing
can take some time (seconds). Writing such a server for Linux is easy,
but Windows is different. I tried several examples and they all failed.
This one keeps working, behaves the same on Linux (Perl 5.8.4) and
Windows (ActivePerl 5.8.8 816), but generates an error message with each
connect:
thread failed to start: Undefined subroutine &main::1 called at [reference
to $thr = threads->new(&process_request($client));]
Does anyone know what is wrong? I don't see how a thread ends.
(Threading is not my thing, until this week I always forked.)
Thanks,
momo
---
#!/usr/bin/perl
use strict;
use threads;
use IO::Socket;
use IO::Select;
my $DONE = 0;
my $path = './';
my ($thr);
$SIG{INT} = $SIG{TERM} = sub { $DONE++ };
my $port = 1080;
my $socket = IO::Socket::INET->new( LocalPort => $port,
Type => SOCK_STREAM,
Listen => SOMAXCONN,
ReuseAddr => 1
) or die "Can't create listen socket: $!";
my $IN = IO::Select->new($socket);
while (!$DONE) {
next unless $IN->can_read;
next unless my $client = $socket->accept;
$thr = threads->new(&process_request($client));
$thr->detach;
}
### process the request
sub process_request {
my $client = $_[0];
local %ENV = ();
my $line = <$client>;
#
#do my thing
#
close $client;
}
--
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 8 at http://www.opera.com
Powered by Outblaze
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs