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

This is a general question since the underlying code is large and complex.

I have a socket client IO::Socket::SSL using blocking sockets.

I create IO::Select and add above socket.

I sysread and syswrite from the socket fine. Then I get the following scenario and I do not know what it is about.

IO::Select::can_read returns my socket indicating there is data to read.

IO::Socket::SSL->pending returns zero meaning there is no data available.

I do a IO::Socket::SSL::sysread on it and it returns zero.

perlfunc sysread says a zero return is end of file, does this mean my socket has disconnected? I keep calling can_read and it keeps repeating. I even create a new IO::Select and can_read still says data is available.

IO::Socket::SSL::connected returns the network address it is suppose to return undef if not connected.

Does anyone know what this means?

Thanx

Replies are listed 'Best First'.
Re: IO::Socket::SSL and IO::Select
by Corion (Patriarch) on Mar 11, 2015 at 08:15 UTC

    Just because there is (maybe) readable data at the TCP level that doesn't mean that there is payload data above the SSL level.

    Have you looked at what the discussion in IO::Socket::SSL has to say about non-blocking sockets?

      Thanx for your reply, I did read that I am using blocking sockets. Does this apply to blocking sockets as well. I guess I can check for EWANTREAD etc. Bodger
Re: IO::Socket::SSL and IO::Select
by noxxi (Pilgrim) on Mar 11, 2015 at 17:54 UTC

    > IO::Select::can_read returns my socket indicating there is data to read.

    can_read does not say that actually data can be read, but that there is something to read on the socket. In your case this "something" tuns out to be nothing, e.g. sysread returns 0. This means end of data, that is the remote end has closed the connection.
      Thank you I was trying to confirm that. It is odd that the $socket->connected does not reflect it.
        The socket is still connected, but the other end announced that it will not send any more data. It might be possible that you still can write data and the peer will accept it.
        This is simply how TCP works and has nothing to do with SSL or Perl.