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)?


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

Replies are listed 'Best First'.
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