oldtomas has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks,

Intro

(NOTE: after this one seemed solved, I hit another snag trying to marry IO::Multiplex and IO::Socket::SSL, which is described here)

I'm trying to build a non-blocking, SSL capable thingie around IO::Multiplex (basically a kind of application proxy, playing the roles of HTTP server and HTTP client).

The non-SSL part is working nicely, now I'm trying to get the SSL part up (just in the client role).

Out of the bewildering array of possibilities I settled fot IO::Socket::SSL. It seems that Multiplex.pm explicitly supports "pseudo" SSL sockets with their somewhat strange behaviour.

As an extra difficulty, I'm behind a proxy, so I have to first send a CONNECT request to the proxy in clear text (this part works).

The Case of the Disappearing fileno

Where I'm stuck is at the attempt to "upgrade" the socket to SSL. That's what I am trying:

sub _sslproxy_done { my($self, $response, $callback) = @_; # We expect here "200 Connection established" unless($response->is_success) { $logger->log(WARN, "Proxy request failed: ", $response->status_line); return; } $logger->log(DEBUG, "Proxy CONNECTed: sock=", $self->{proxy_requestor}->sock, " fileno=", fileno($self->{proxy_requestor}->sock)); $self->{sslsock} = $self->{proxy_requestor}->sock; unless(IO::Socket::SSL->start_SSL($self->{sslsock}, SSL_startHandshake => 0)) { $logger->log(DEBUG, "start_SSL returns false"); return; } for(;;) { # Later do asynchronously! $logger->log(DEBUG, "connect_SSL..."); $self->{sslsock}->connect_SSL && last; $logger->log(DEBUG, "connect_SSL: $SSL_ERROR"); } $logger->log(DEBUG, "_sslproxy_done() sslsock=", $self->{sslsock}, " opened=", $self->{sslsock} && $self->{sslsock}->opened); goto &$callback if($self->{sslsock}); $logger->log(WARN, "start_SSL error: ", IO::Socket::SSL::errstr() || "Unknown"); }

Before calling IO::Socket::SSL->start_SSL(...) above, the debugging function dutifully says:

1337867878.449198 [Mumble::Backend::query]: Proxy CONNECTed: sock=bles +s( \*Symbol::GEN2, 'IO::Socket::INET' ) fileno=7 at Mumble::Backend:: +query line 582

Note the fileno=7 there?

But within IO::Socket::SSL::start_SSL (I have a local copy which I can augment with DEBUG calls as needed), I see:

DEBUG: .../IO/Socket/SSL.pm:991: socket = IO::Socket::INET=GLOB(0x18e1 +dc0) fileno=

EEEK! This looks completely different! Besides: where's my fileno?

Needles to say, we run into problems when trying to "connect_SSL" that:

DEBUG: .../IO/Socket/SSL.pm:1546: new ctx 26143712 DEBUG: .../IO/Socket/SSL.pm:1017: dont start handshake: IO::Socket::SS +L=GLOB(0x18e1dc0) DEBUG: .../IO/Socket/SSL.pm:349: ssl handshake not started 1337867878.451761 [Mumble::Backend::query]: connect_SSL... at Mumble:: +Backend::query line 589 DEBUG: .../IO/Socket/SSL.pm:1277: Socket has no filenoerror:00000000:l +ib(0):func(0):reason(0)

Shared file handles for select?

One more question:

When I upgrade a IO::Socket::INET to an SSL they will share the file handle? I.e. for IO::Multiplex they are the same?

If yes, I'd better detach the "old, plain socket" from IO::Multiplex before I attach the upgraded SSL socket, right?

Are there any examples out there for this combination?

Replies are listed 'Best First'.
Answer to self: yes, I have to remove the filehandle from IO::Multiplex first
by oldtomas (Novice) on May 25, 2012 at 10:11 UTC

    Hi,

    this is to share my (first) findings: IO::Multiplex ties the file handles given to it. IO::Socket::SSL's ->start_SSL doesn't like tied handles.

    Doing

    $Mux->remove($self->{sslsock});
    (where $Mux is a ref to the IO::Multiplex instance) does the trick.