in reply to Can I/O operations on the same IO::Socket be executed in different threads?

Is this also true also for IO::Socket::SSL sockets (assuming a recent version of Net::SSLeay)?
As long as these actions are locked against each other and thus do not happen at the same time it should be safe enough. Without locking: no. It is better to restrict yourself so that all actions on the same socket are done in the same thread.
  • Comment on Re: Can I/O operations on the same IO::Socket be executed in different threads?

Replies are listed 'Best First'.
Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
by Anonymous Monk on May 13, 2015 at 00:27 UTC

    Just to clarify—you are saying that the concerns in IO::Socket::SSL + fork problem do not apply in this case?

    How do you envision such socket being managed? Perusing threads::shared and my $sock :shared; will ensure coherent state? The Net::SSLeay itself is thread-safe, but does it support shared sockets? Any special concerns, such as nonblocking mode or cross-thread callbacks?

      Once the SSL socket is established all the necessary state for reading and writing is fully managed by the OpenSSL library. That is the Perl socket can be used between multiple threads, but only one thread should use the socket at one time (i.e. needs locking). Forking is different because in this case the SSL state gets duplicated and client and server try to manage their own state independently which will not work because then none of these will reflect the real state of the SSL connection.

      Of course all this means that the Socket must be created before the threads are created. Creating a socket in one thread and then using it in another will not work since the Perl handle can not be shared.

Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
by locked_user sundialsvc4 (Abbot) on May 12, 2015 at 23:35 UTC

    And yet, one thought that keeps banging against my head is this:   “even if we can ‘make it to work,” does it ‘make sense?’”   That, to me, is actually a key question here:   “does it actually ‘make sense’ that one thread should ‘only read,’ and that another thread, ‘only write?’”   I don’t think so.   Why?   Because somebody needs to be aware of:   “the present-state of the remote client.”   And, furthermore, this “present-state” can only be ascertained, subject to an unforeseen (and, unforeseeable ...) lag.

    Therefore, I suggest that the only truly-practicable design must be this:   “put your letter in the box, raise the flag, and then wait for the postman.”   “The Postman” has no race-conditions within himself.   Therefore, he is able to efficiently serve the needs of any number of clients without conflict.

    To my way of thinking, both of the client-processes in question should be reading/writing from queues that are served by the Postman.   They should not be attempting to read/write from the socket directly.