in reply to Re: IO::Multiplex and tied handles?
in thread IO::Multiplex and tied handles?

There seems to exist a solution (phew)

Handwaving

Very lightly tested, and it might depend heavily on the details of the tied handle, but this approach already showed some "signs of life"

The gist is, you have to stash away the tied object before re-tieing it, and then delegate to its methods when it comes to reading and writing.

Show me the code

In the case of IO::Multiplex and IO::Socket::SSL that means:

Stash away the tied object

In IO::Multiplex's add method, stash away the tied object before it gets steamrolled by the new tie()

sub add { [...] $self->{_fhs}{"$fh"}{oldtie} = tied(*$fh) if defined(tied(*$fh)); $self->{_handles}{"$fh"} = $fh; tie *$fh, "IO::Multiplex::Handle", $self, $fh; return $fh; }

Delegate read, write to the stashed-away object, fall back to POSIX::read and POSIX::write

Somewhere in IO::Multiplex's loop method, replace the direct calls to POSIX::read resp. POSIX::write by those two code snippets:
$rv = ($self->{_fhs}{"$fh"}{oldtie}) ? $self->{_fhs}{"$fh"}{oldtie}->READ($data, BUFSIZ) : &POSIX::read(fileno($fh), $data, BUFSIZ);
resp.
$rv = ($self->{_fhs}{"$fh"}{oldtie}) ? $self->{_fhs}{"$fh"}{oldtie}->READ($data, BUFSIZ) : &POSIX::read(fileno($fh), $data, BUFSIZ);

Caveats

This code is in the "I-tried-it-once-and-it-seemed-to-work" category. Use with care.

Don't forget goggles and gloves.