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
- #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
- #to_s ⇒ Object
- #version ⇒ Object
-
#viable? ⇒ Boolean
Can we use this connection to make requests?.
- #write_frame(frame) ⇒ Object
- #write_frames(&block) ⇒ Object
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
121 122 123 |
# File 'lib/async/http/protocol/http2/connection.rb', line 121 def count @count end |
#promises ⇒ Object (readonly)
Returns the value of attribute promises.
115 116 117 |
# File 'lib/async/http/protocol/http2/connection.rb', line 115 def promises @promises end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
42 43 44 |
# File 'lib/async/http/protocol/http2/connection.rb', line 42 def stream @stream end |
Instance Method Details
#close(error = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/async/http/protocol/http2/connection.rb', line 56 def close(error = nil) super # Ensure the reader task is stopped. if @reader reader = @reader @reader = nil reader.stop end end |
#concurrency ⇒ Object
123 124 125 |
# File 'lib/async/http/protocol/http2/connection.rb', line 123 def concurrency self.maximum_concurrent_streams end |
#http1? ⇒ Boolean
44 45 46 |
# File 'lib/async/http/protocol/http2/connection.rb', line 44 def http1? false end |
#http2? ⇒ Boolean
48 49 50 |
# File 'lib/async/http/protocol/http2/connection.rb', line 48 def http2? true end |
#initialize ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/async/http/protocol/http2/connection.rb', line 28 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
117 118 119 |
# File 'lib/async/http/protocol/http2/connection.rb', line 117 def peer @stream.io end |
#read_in_background(parent: Task.current) ⇒ Object
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 112 113 |
# File 'lib/async/http/protocol/http2/connection.rb', line 84 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}.") begin while !self.closed? self.consume_window self.read_frame end rescue SocketError, IOError, EOFError, Errno::ECONNRESET, Errno::EPIPE, Async::Wrapper::Cancelled # Ignore. rescue ::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. if @reader self.close(error) end ensure # Don't call #close twice. if @reader self.close($!) end end end end |
#reusable? ⇒ Boolean
132 133 134 |
# File 'lib/async/http/protocol/http2/connection.rb', line 132 def reusable? !self.closed? end |
#start_connection ⇒ Object
52 53 54 |
# File 'lib/async/http/protocol/http2/connection.rb', line 52 def start_connection @reader || read_in_background end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/async/http/protocol/http2/connection.rb', line 38 def to_s "\#<#{self.class} #{@streams.count} active streams>" end |
#version ⇒ Object
136 137 138 |
# File 'lib/async/http/protocol/http2/connection.rb', line 136 def version VERSION end |
#viable? ⇒ Boolean
Can we use this connection to make requests?
128 129 130 |
# File 'lib/async/http/protocol/http2/connection.rb', line 128 def viable? @stream.connected? end |
#write_frame(frame) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/async/http/protocol/http2/connection.rb', line 67 def write_frame(frame) # We don't want to write multiple frames at the same time. @write_frame_guard.acquire do super end @stream.flush end |
#write_frames(&block) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/async/http/protocol/http2/connection.rb', line 76 def write_frames(&block) @write_frame_guard.acquire do super end @stream.flush end |