bumby has asked for the wisdom of the Perl Monks concerning the following question:
I have the following basic code structure:
a main program with a thread pool accepting tcp connections all data received from these connections are put on a thread queue which another thread handles
the "other" thread: this thread has got an irc-connection (Net::IRC) with an infinite while-loop which first handles irc-stuff (do_one_loop) and secondly dequeues the previous mentioned queue.
All irc-events are forwarded to another (or actually several other) tcp-connections (the brains). These brains are separate programs which handles the events, generate replies and send these back via tcp to the main-part (which will queue and be dequeued by irc-thread and printed to channel or whatever).Now, this all works fine. The problem I'm having is that I want my program to, in a good fashion, reconnect to any lost brain connection. So that if any brain is restarted, it will be reconnected again. I've set SIGPIPE to ignore and successfully detect deconnected brain-connections. The brain connections are stored in a hash with connection-numbers as keys (0, 1, 2, ...). Once a connection is detected as lost its key (connection number) is put on a reconnect-queue, which a reconnect thread dequeues and then tries to reconnect to this connection. ($brains->{$key}->{Socket} = IO::Socket::INET->new...)
Now, of course, this doesn't work, since this brains-hash will be a separate copy from the one in the irc-thread. Or at least that's how I've understood it. I've tried sending references to the thread too, but it seems to have the same effect.So my question basically boils down to this: How can I reconnect IO::Socket::INET connections in a separate thread?
I want this to be done in a separate (detached) thread to avoid the irc-thread to get stuck while trying to connect to brains.
Is this even possible? Or should I just set these connection to nonblocking and call it a day?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sharing (io::socket) objects with threads
by TOD (Friar) on May 17, 2007 at 02:25 UTC | |
by BrowserUk (Patriarch) on May 17, 2007 at 03:27 UTC | |
by chrism01 (Friar) on May 17, 2007 at 05:53 UTC | |
by bumby (Beadle) on May 17, 2007 at 11:47 UTC | |
|
Re: sharing (io::socket) objects with threads
by BrowserUk (Patriarch) on May 17, 2007 at 01:30 UTC | |
|
Re: sharing (io::socket) objects with threads
by chrism01 (Friar) on May 17, 2007 at 05:47 UTC | |
|
Re: sharing (io::socket) objects with threads
by zentara (Cardinal) on May 17, 2007 at 12:15 UTC |