def read(length)
      data = ''
      while data.length < length
        begin
          toRead = length-data.length
          rateLimited = false
          if @ioInfo.readRateLimit
            avail = @ioInfo.readRateLimit.avail.to_i
            if avail < toRead
              toRead = avail
              rateLimited = true
            end
            @ioInfo.readRateLimit.withdraw toRead
          end
          @logger.debug "IoFacade: must read: #{length} have read: #{data.length}. Reading #{toRead} bytes now" if @logger
          data << @io.read_nonblock(toRead) if toRead > 0
          # If we tried to read more than we are allowed to by rate limiting, yield.
          Fiber.yield if rateLimited
        rescue Errno::EWOULDBLOCK
          # Wait for more data.
          @logger.debug "IoFacade: read would block" if @logger
          Fiber.yield
        rescue Errno::EAGAIN, Errno::EINTR
          # Wait for more data.
          @logger.debug "IoFacade: read was interrupted" if @logger
          Fiber.yield
        rescue
          @logger.debug "IoFacade: read error: #{$!}" if @logger
          # Read failure occurred
          @ioInfo.lastReadError = $!
          if @ioInfo.useErrorhandler
            @ioInfo.state = :error
            Fiber.yield
          else
            raise $!
          end
        end
      end
      data
    end
def read(length)
      data = ''
      while data.length < length
        begin
          toRead = length-data.length
          rateLimited = false
          if @ioInfo.readRateLimit
            avail = @ioInfo.readRateLimit.avail.to_i
            if avail < toRead
              toRead = avail
              rateLimited = true
            end
            @ioInfo.readRateLimit.withdraw toRead
          end
          @logger.debug "IoFacade: must read: #{length} have read: #{data.length}. Reading #{toRead} bytes now" if @logger
          data << @io.read_nonblock(toRead) if toRead > 0
          # If we tried to read more than we are allowed to by rate limiting, yield.
          Fiber.yield if rateLimited
        rescue Errno::EWOULDBLOCK
          # Wait for more data.
          @logger.debug "IoFacade: read would block" if @logger
          Fiber.yield
        rescue Errno::EAGAIN, Errno::EINTR
          # Wait for more data.
          @logger.debug "IoFacade: read was interrupted" if @logger
          Fiber.yield
        rescue
          @logger.debug "IoFacade: read error: #{$!}" if @logger
          # Read failure occurred
          @ioInfo.lastReadError = $!
          if @ioInfo.useErrorhandler
            @ioInfo.state = :error
            Fiber.yield
          else
            raise $!
          end
        end
      end
      data
    end
Read `length` bytes.