i didn't really share the socket as it was :)
relook at the code , i wasn't "really" sharing the client socket
u can draw the processes on a piece of paper and see that
only one thread uses the real $client :)
the other one looses it just after ... and none dies ....


 Martin - [hurray for the keyboards, lol]

#$%>-----Original Message-----
#$%>From: Ray Hilton [mailto:[EMAIL PROTECTED]]
#$%>Sent: Thursday, October 10, 2002 12:46 PM
#$%>To: 'Martin Roos'; 'Perl-Ithreads'
#$%>Subject: RE: IO::Socket and iThreads (and Thread::Pool)
#$%>
#$%>
#$%>Does that work for you?  That is similar to what I was trying and the
#$%>limitation is that $client is a GLOB and you cannot share GLOBs (yet) so
#$%>when you tried to pass the value to the handler() function it die()d.
#$%>
#$%>What I have done though, is create a pool of threads for the
#$%>application, and fork() on a new tcp connection, this copies the whole
#$%>process space, including the thread pool, instantly, so this seems to
#$%>work fine as there is no reason for each process (per tcp socket) to
#$%>return to the main process.
#$%>
#$%>-----Original Message-----
#$%>From: Martin Roos [mailto:[EMAIL PROTECTED]]
#$%>Sent: 10 October 2002 06:18
#$%>To: Perl-Ithreads
#$%>Subject: RE: IO::Socket and iThreads (and Thread::Pool)
#$%>
#$%>i might be missing a point in the question
#$%>anyway, the following program worked by
#$%>me. a tricky thing was that the $client in
#$%>the while loop had to go out of scope so
#$%>the socket could really have been closed.
#$%>if i declared it before the while loop
#$%>it seemed to lock somehow, anyway, there
#$%>was no way to close it then. i reorganized
#$%>my code then and put the $client variable
#$%>into the while loop block, when it lost the scope
#$%>in while and the client thread said $client->close();
#$%>it really closed itself up.
#$%>
#$%> Martin
#$%>
#$%>my program looks like this :
#$%>
#$%>
#$%>
#$%>#!/usr/bin/perl
#$%>use strict;
#$%># do we still need this ?
#$%>use Socket;
#$%>use threads;
#$%>use threads::shared;
#$%>use logger;
#$%>use IO::Socket;
#$%>
#$%>$| = 1;
#$%>
#$%>my $EOL = "\015\012";
#$%>my $proto = "tcp";
#$%>my $port = 15300;
#$%>
#$%>debug("Trying to bind a socket");
#$%>
#$%>my ($server);
#$%>
#$%>$server = IO::Socket::INET->new (Listen     => SOMAXCONN,
#$%>    LocalPort => $port,
#$%>    Proto     => 'tcp',
#$%>    Blocking        => 0,
#$%>    Reuse     => 1);
#$%>die "can't setup server" unless $server;
#$%>
#$%>debug("waiting for connection");
#$%>while ( 1 > 0) {
#$%>    my $client = $server->accept();
#$%>    debug("spooky, we got a client from
#$%>(".$client->peerhost().":".$client->peerport().")");
#$%>    threads->create(\&handler,$client);
#$%>    debug("waiting for another connection");
#$%>}
#$%>
#$%>debug("all done");
#$%>
#$%>sub handler() {
#$%>    my $client;
#$%>    $client = pop @_;
#$%>    $client->autoflush(1);
#$%>    print $client "Hello Hello $EOL";
#$%>    $client->close();
#$%>    debug("handled a client");
#$%>}
#$%>
#$%>

Reply via email to