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.


In reply to Re^2: IO::Multiplex and tied handles? by oldtomas
in thread IO::Multiplex and tied handles? by oldtomas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.