Sha256: bed335434b68cbfc08cc703f6cc5b90de38a703d646f44136beee8310922683a

Contents?: true

Size: 1.63 KB

Versions: 22

Compression:

Stored size: 1.63 KB

Contents

module Bunny
  module JRuby
    begin
      require "bunny/cruby/ssl_socket"
      require "openssl"

      # TLS-enabled TCP socket that implements convenience
      # methods found in Bunny::Socket.
      class SSLSocket < Bunny::SSLSocket

        def initialize(*args)
          super
          @__bunny_socket_eof_flag__ = false
        end

        # Reads given number of bytes with an optional timeout
        #
        # @param [Integer] count How many bytes to read
        # @param [Integer] timeout Timeout
        #
        # @return [String] Data read from the socket
        # @api public
        def read_fully(count, timeout = nil)
          return nil if @__bunny_socket_eof_flag__

          value = ''
          begin
            loop do
              value << read_nonblock(count - value.bytesize)
              break if value.bytesize >= count
            end
          rescue EOFError => e
            @__bunny_socket_eof_flag__ = true
          rescue OpenSSL::SSL::SSLError => e
            if e.message == "read would block"
              if IO.select([self], nil, nil, timeout)
                retry
              else
                raise Timeout::Error, "IO timeout when reading #{count} bytes"
              end
            else
              raise e
            end
          rescue *READ_RETRY_EXCEPTION_CLASSES => e
            if IO.select([self], nil, nil, timeout)
              retry
            else
              raise Timeout::Error, "IO timeout when reading #{count} bytes"
            end
          end
          value
        end
      end
    rescue LoadError => le
      puts "Could not load OpenSSL"
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
bunny-2.23.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.22.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.21.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.20.3 lib/bunny/jruby/ssl_socket.rb
bunny-2.20.2 lib/bunny/jruby/ssl_socket.rb
bunny-2.20.1 lib/bunny/jruby/ssl_socket.rb
bunny-2.20.0 lib/bunny/jruby/ssl_socket.rb
garaio_bunny-2.19.2 lib/bunny/jruby/ssl_socket.rb
garaio_bunny-2.19.1 lib/bunny/jruby/ssl_socket.rb
bunny-2.19.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.18.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.17.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.16.1 lib/bunny/jruby/ssl_socket.rb
bunny-2.15.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.14.4 lib/bunny/jruby/ssl_socket.rb
bunny-2.14.3 lib/bunny/jruby/ssl_socket.rb
bunny-2.14.2 lib/bunny/jruby/ssl_socket.rb
bunny-2.14.1 lib/bunny/jruby/ssl_socket.rb
bunny-2.13.0 lib/bunny/jruby/ssl_socket.rb
bunny-2.12.1 lib/bunny/jruby/ssl_socket.rb