CC: | <tomas [...] tuxteam.de> |
Subject: | [PATCH] IO::Multiplex and IO::Socket::SSL |
Date: | Tue, 29 May 2012 10:37:37 +0200 |
To: | <bug-IO-Multiplex [...] rt.cpan.org> |
From: | Tomas Zerolo <tomas.zerolo [...] axelspringer.de> |
Hi,
I'm trying to build an asynchronous SSL client around IO::Multiplex.
I refer to the version 1.13 of IO::Multiplex as distributed by
Debian Wheezy (libio-multiplex-perl 1.13-1).
I managed to get at a point where I "see" a garbage answer from the
server (which might be encripted stuff.
Looking into IO::Multiplex's source, I see that it POSIX::read()s
from and POSIX::write()s to the underlying file descriptor, thus
bypassing the SSL layer bound onto it by IO::Socket::SSL.
My attempt to solve it is by trying to delegate to the READ and
WRITE methods of the bound object (and to fall back to POSIX::read
and POSIX::write if the socket wasn't bound).
See <http://www.perlmonks.org/?node_id=972687> for a more detailed
write-up.
Here's a tentative patch which "has been seen to work once":
--- original/perl5/IO/Multiplex.pm 2011-04-15 08:40:23.000000000 +0200
+++ modified/perl5/IO/Multiplex.pm 2012-05-29 09:47:51.821377686 +0200
@@ -362,6 +362,7 @@
$self->{_fhs}{"$fh"}{inbuffer} = '';
$self->{_fhs}{"$fh"}{outbuffer} = '';
$self->{_fhs}{"$fh"}{fileno} = fileno($fh);
+ $self->{_fhs}{"$fh"}{oldtie} = tied(*$fh) if defined(tied(*$fh));
$self->{_handles}{"$fh"} = $fh;
tie *$fh, "IO::Multiplex::Handle", $self, $fh;
return $fh;
@@ -645,7 +646,9 @@
$self->{_fhs}{"$fh"}{udp_peer} = $rv;
}
} else {
- $rv = &POSIX::read(fileno($fh), $data, BUFSIZ);
+ $rv = ($self->{_fhs}{"$fh"}{oldtie})
+ ? $self->{_fhs}{"$fh"}{oldtie}->READ($data, BUFSIZ)
+ : &POSIX::read(fileno($fh), $data, BUFSIZ);
}
if (defined($rv) && length($data)) {
@@ -699,8 +702,12 @@
if ($obj && $obj->can("mux_outbuffer_empty"));
next;
}
- $rv = &POSIX::write(fileno($fh),
- $self->{_fhs}{"$fh"}{outbuffer},
+ $rv = ($self->{_fhs}{"$fh"}{oldtie})
+ ? $self->{_fhs}{"$fh"}{oldtie}->WRITE(
+ $self->{_fhs}{"$fh"}{outbuffer},
+ length($self->{_fhs}{"$fh"}{outbuffer}))
+ : &POSIX::write(fileno($fh),
+ $self->{_fhs}{"$fh"}{outbuffer},
length($self->{_fhs}{"$fh"}{outbuffer}));
unless (defined($rv)) {
# We got an error writing to it. If it's
BTW: thanks for IO::Multiplex!
--
Tomás Zerolo
Axel Springer AG
Axel Springer media Systems
BILD Produktionssysteme
Axel-Springer-Straße 65
10888 Berlin
Tel.: +49 (30) 2591-72875
tomas.zerolo@axelspringer.de
www.axelspringer.de
Axel Springer AG, Sitz Berlin, Amtsgericht Charlottenburg, HRB 4998
Vorsitzender des Aufsichtsrats: Dr. Giuseppe Vita
Vorstand: Dr. Mathias Döpfner (Vorsitzender)
Jan Bayer, Ralph Büchi, Lothar Lanz, Dr. Andreas Wiele