Sha256: 7c4e8992dccbe973c72c89cfdf8c9183a0ac7e4ac53e8c54923d4241cf1ad771

Contents?: true

Size: 1.14 KB

Versions: 22

Compression:

Stored size: 1.14 KB

Contents

require "bunny/cruby/socket"

module Bunny
  module JRuby
    # TCP socket extension that uses Socket#readpartial to avoid excessive CPU
    # burn after some time. See issue #165.
    # @private
    module Socket
      include Bunny::Socket

      # 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 << readpartial(count - value.bytesize)
            break if value.bytesize >= count
          end
        rescue EOFError
          # @eof will break Rubinius' TCPSocket implementation. MK.
          @__bunny_socket_eof_flag__ = true
        rescue *READ_RETRY_EXCEPTION_CLASSES
          if IO.select([self], nil, nil, timeout)
            retry
          else
            raise Timeout::Error, "IO timeout when reading #{count} bytes"
          end
        end
        value
      end # read_fully
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bunny-2.6.7 lib/bunny/jruby/socket.rb
bunny-2.7.2 lib/bunny/jruby/socket.rb
bunny-2.7.1 lib/bunny/jruby/socket.rb
bunny-2.7.0 lib/bunny/jruby/socket.rb
bunny-2.6.6 lib/bunny/jruby/socket.rb
bunny-2.6.5 lib/bunny/jruby/socket.rb
bunny-2.6.4 lib/bunny/jruby/socket.rb
bunny-2.6.3 lib/bunny/jruby/socket.rb
bunny-2.6.2 lib/bunny/jruby/socket.rb
bunny-2.6.1 lib/bunny/jruby/socket.rb
bunny-2.6.0 lib/bunny/jruby/socket.rb
bunny-2.5.1 lib/bunny/jruby/socket.rb
bunny-2.5.0 lib/bunny/jruby/socket.rb
bunny-2.4.0 lib/bunny/jruby/socket.rb
bunny-2.3.1 lib/bunny/jruby/socket.rb
bunny-2.3.0 lib/bunny/jruby/socket.rb
bunny-2.2.2 lib/bunny/jruby/socket.rb
bunny-2.2.1 lib/bunny/jruby/socket.rb
bunny-2.2.0 lib/bunny/jruby/socket.rb
bunny-1.7.1 lib/bunny/jruby/socket.rb