exaethier has asked for the wisdom of the Perl Monks concerning the following question:
sub mainThread
{
my $d = HTTP::Daemon->new();
// $c is a descendent of IO::Handle
while ( my $c = $d->accept )
{
// pass fileno($c) to a thread-shared queue where it will be picked
// up by a worker thread
// at the close of this loop $c drops out of scope and the socket is
// closed, even though the workerThread is still using it
}
}
sub workerThread
{
my $fileno = shift;
my $c;
open $c, '+<&=' . $fileno;
// generate a response and write to $c
close $c;
}
The only solution I have found involves maintaining a list of handles in the main thread and dropping them after the worker thread indicates it is done, however there must be a cleaner way to do this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Preventing IO::Handles from closing on destruction
by Eliya (Vicar) on Nov 04, 2011 at 15:07 UTC | |
by exaethier (Initiate) on Nov 04, 2011 at 15:36 UTC | |
by Eliya (Vicar) on Nov 04, 2011 at 15:55 UTC | |
by exaethier (Initiate) on Nov 04, 2011 at 18:30 UTC |