Module: Async::HTTP::Protocol::HTTP2::Connection
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#promises ⇒ Object
readonly
Returns the value of attribute promises.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #as_json ⇒ Object
- #close(error = nil) ⇒ Object
- #concurrency ⇒ Object
- #http1? ⇒ Boolean
- #http2? ⇒ Boolean
- #initialize ⇒ Object
- #peer ⇒ Object
- #read_in_background(parent: Task.current) ⇒ Object
- #reusable? ⇒ Boolean
- #start_connection ⇒ Object
- #synchronize(&block) ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #version ⇒ Object
-
#viable? ⇒ Boolean
Can we use this connection to make requests?.
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
119 120 121 |
# File 'lib/async/http/protocol/http2/connection.rb', line 119 def count @count end |
#promises ⇒ Object (readonly)
Returns the value of attribute promises.
113 114 115 |
# File 'lib/async/http/protocol/http2/connection.rb', line 113 def promises @promises end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
55 56 57 |
# File 'lib/async/http/protocol/http2/connection.rb', line 55 def stream @stream end |
Instance Method Details
#as_json ⇒ Object
47 48 49 |
# File 'lib/async/http/protocol/http2/connection.rb', line 47 def as_json(...) to_s end |
#close(error = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/async/http/protocol/http2/connection.rb', line 69 def close(error = nil) # Ensure the reader task is stopped. if @reader reader = @reader @reader = nil reader.stop end super end |
#concurrency ⇒ Object
121 122 123 |
# File 'lib/async/http/protocol/http2/connection.rb', line 121 def concurrency self.maximum_concurrent_streams end |
#http1? ⇒ Boolean
57 58 59 |
# File 'lib/async/http/protocol/http2/connection.rb', line 57 def http1? false end |
#http2? ⇒ Boolean
61 62 63 |
# File 'lib/async/http/protocol/http2/connection.rb', line 61 def http2? true end |
#initialize ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/async/http/protocol/http2/connection.rb', line 29 def initialize(*) super @count = 0 @reader = nil # Writing multiple frames at the same time can cause odd problems if frames are only partially written. So we use a semaphore to ensure frames are written in their entirety. @write_frame_guard = Async::Semaphore.new(1) end |
#peer ⇒ Object
115 116 117 |
# File 'lib/async/http/protocol/http2/connection.rb', line 115 def peer @peer ||= ::Protocol::HTTP::Peer.for(@stream.io) end |
#read_in_background(parent: Task.current) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/async/http/protocol/http2/connection.rb', line 80 def read_in_background(parent: Task.current) raise RuntimeError, "Connection is closed!" if closed? parent.async(transient: true) do |task| @reader = task task.annotate("#{version} reading data for #{self.class}.") # We don't need to defer stop here as this is already a transient task (ignores stop): begin while !self.closed? self.consume_window self.read_frame end rescue Async::Stop, ::IO::TimeoutError, ::Protocol::HTTP2::GoawayError => error # Error is raised if a response is actively reading from the # connection. The connection is silently closed if GOAWAY is # received outside the request/response cycle. rescue SocketError, IOError, EOFError, Errno::ECONNRESET, Errno::EPIPE => ignored_error # Ignore. rescue => error # Every other error. ensure # Don't call #close twice. if @reader @reader = nil self.close(error) end end end end |
#reusable? ⇒ Boolean
130 131 132 |
# File 'lib/async/http/protocol/http2/connection.rb', line 130 def reusable? !self.closed? end |
#start_connection ⇒ Object
65 66 67 |
# File 'lib/async/http/protocol/http2/connection.rb', line 65 def start_connection @reader || read_in_background end |
#synchronize(&block) ⇒ Object
39 40 41 |
# File 'lib/async/http/protocol/http2/connection.rb', line 39 def synchronize(&block) @write_frame_guard.acquire(&block) end |
#to_json ⇒ Object
51 52 53 |
# File 'lib/async/http/protocol/http2/connection.rb', line 51 def to_json(...) as_json.to_json(...) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/async/http/protocol/http2/connection.rb', line 43 def to_s "\#<#{self.class} #{@count} requests, #{@streams.count} active streams>" end |
#version ⇒ Object
134 135 136 |
# File 'lib/async/http/protocol/http2/connection.rb', line 134 def version VERSION end |
#viable? ⇒ Boolean
Can we use this connection to make requests?
126 127 128 |
# File 'lib/async/http/protocol/http2/connection.rb', line 126 def viable? @stream&.readable? end |