Class: Net::BufferedIO

Inherits:
Object
  • Object
show all
Defined in:
lib/midori-contrib/net.rb

Overview

Meta programming Net class for async HTTP and FTP connection

Instance Method Summary collapse

Instance Method Details

#rbuf_fillObject

Fill until the operation finishes



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/midori-contrib/net.rb', line 19

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

#wait_io(interest) ⇒ Object

Wait till io finishes



8
9
10
11
12
13
14
15
16
# File 'lib/midori-contrib/net.rb', line 8

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