in reply to Keeping an INET socket inside a shared object
I haven't found any good mechanism for sharing IO::Socket::INET objects between threads.
(I'm the guy that 'discovered' the fileno trick for sharing file handles; so I know a little about this. :)
This is doubly true if those shared objects encapsulate process-global entities like sockets, filehandles, directory handles etc.
Think about this:
Whilst sockets are bi-directional, they are serially bi-directional, which is to say they can only be communicating in one direction at any given time.
With a single thread handling a socket, it is easy to manage that it send something, then reads the reply, sends something, then reads the reply. (Or waits for input then responds...)
But coordinating between multiple threads becomes fraught with opportunities for deadlocks and infinite blocks.
In short, a shared object architecture makes no sense when dealing with sockets.
The correct alternatives are:
|
|---|