Sha256: 8f9696d4fe5d95ee2447fd60b4bb0ad8bfde1f738449672668ba656771a1c66c

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

require 'net/protocol'

##
# Meta programming Net class for async HTTP and FTP connection
class Net::BufferedIO
  # Wait till io finishes
  # @param [Symbol] interest
  def wait_io(interest)
    await(Promise.new do |resolve|
      io = @io.to_io
      EventLoop.register(io, interest) do
        EventLoop.deregister(io)
        resolve.call(self)
      end
    end)
  end

  # Fill until the operation finishes
  def rbuf_fill
    loop do
      case rv = @io.read_nonblock(BUFSIZE, exception: false)
        when String
          return @rbuf << rv
        when :wait_readable
          wait_io(:r)
        # @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
        # continue looping
        when :wait_writable
          # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
          # http://www.openssl.org/support/faq.html#PROG10
          # :nocov:
          wait_io(:w)
        # @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
        # continue looping
        when nil
          # callers do not care about backtrace, so avoid allocating for it
          raise EOFError, 'end of file reached', []
        # :nocov:
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
midori-contrib-0.1.3 lib/midori-contrib/net.rb
midori-contrib-0.1.2 lib/midori-contrib/net.rb
midori-contrib-0.1.1 lib/midori-contrib/net.rb
midori-contrib-0.1.0 lib/midori-contrib/net.rb
midori-contrib-0.0.2 lib/midori-contrib/net.rb
midori-contrib-0.0.1 lib/midori-contrib/net.rb
em-midori-0.3.0 lib/midori/extension/net.rb
em-midori-0.2.4 lib/midori/extension/net.rb
em-midori-0.2.3 lib/midori/extension/net.rb
em-midori-0.2.2 lib/midori/extension/net.rb
em-midori-0.2.1 lib/midori/extension/net.rb