Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
XP is just a number
 
PerlMonks  

Re^2: Thread::Queue and objects

by bronto (Priest)
on Jan 14, 2005 at 15:11 UTC ( #422259=note: print w/ replies, xml ) Need Help??


in reply to Re: Thread::Queue and objects
in thread Thread::Queue and objects

Ok, but... how would you make goto END a thread that is stuck in blocking call (a socket accept in this case)?

Ciao!
--bronto


In theory, there is no difference between theory and practice. In practice, there is.


Comment on Re^2: Thread::Queue and objects
Select or Download Code
Re^3: Thread::Queue and objects
by zentara (Archbishop) on Jan 15, 2005 at 12:47 UTC
    Caveat: I'm not sure exactly what code you are referring to, and I havn't tested this. But I'm guessing you mean the following worker thread code block, which I would try to modify like the following. If you are blocking somewhere on a socket, maybe setup a timeout alarm on the connection, or use sysread or one of the other tricks to prevent blocking. All you really need to do, is somehow keep the thread looping, and periodically checking for $die.
    #in your main share $die; $die = 0; .... #set $die =1 when you want to exit or kill the thread ...... #worker code block sub httpd { LISTEN: { my $client = $httpd->accept ; goto END if $die; redo LISTEN unless defined $client ; my $request = $client->get_request ; unless ($request->method eq 'POST' and $request->url->path eq '/message') { $client->send_error(RC_FORBIDDEN) ; $client->close ; goto END if $die; redo LISTEN ; } my $q = CGI->new($request->content) ; my ($nick,$message) = map $q->param($_),qw(nick message) ; print STDERR "Resetting text box state\n" if DEBUG ; $tbox->configure(-state => 'normal') ; $tbox->insert('end',qq($nick says: $message\n)) ; print STDERR "Disabling text box\n" if DEBUG ; $tbox->configure(-state => 'disabled') ; $client->send_status_line ; $client->close ; goto END if $die; redo LISTEN ; } END: }

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-04-18 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (461 votes), past polls