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

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?

  • Comment on Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
  • Download Code

Replies are listed 'Best First'.
Re^3: Can I/O operations on the same IO::Socket be executed in different threads?
by noxxi (Pilgrim) on May 13, 2015 at 19:09 UTC

    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.