Class: Plum::Connection
- Inherits:
-
Object
- Object
- Plum::Connection
- Includes:
- ConnectionUtils, EventEmitter, FlowControl
- Defined in:
- lib/plum/connection.rb
Direct Known Subclasses
Constant Summary collapse
- CLIENT_CONNECTION_PREFACE =
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".freeze
- DEFAULT_SETTINGS =
{ header_table_size: 4096, # octets enable_push: 1, # 1: enabled, 0: disabled max_concurrent_streams: 1 << 30, # (1 << 31) / 2 initial_window_size: 65535, # octets; <= 2 ** 31 - 1 max_frame_size: 16384, # octets; <= 2 ** 24 - 1 max_header_list_size: (1 << 32) - 1 # Fixnum }.freeze
Instance Attribute Summary collapse
-
#hpack_decoder ⇒ Object
readonly
Returns the value of attribute hpack_decoder.
-
#hpack_encoder ⇒ Object
readonly
Returns the value of attribute hpack_encoder.
-
#local_settings ⇒ Object
readonly
Returns the value of attribute local_settings.
-
#remote_settings ⇒ Object
readonly
Returns the value of attribute remote_settings.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
Attributes included from FlowControl
#recv_remaining_window, #send_remaining_window
Instance Method Summary collapse
-
#close ⇒ Object
Emits :close event.
-
#receive(new_data) ⇒ Object
(also: #<<)
Receives the specified data and process.
-
#reserve_stream(**args) ⇒ Object
Reserves a new stream to server push.
Methods included from ConnectionUtils
#goaway, #ping, #push_enabled?, #settings
Methods included from FlowControl
Methods included from EventEmitter
Instance Attribute Details
#hpack_decoder ⇒ Object (readonly)
Returns the value of attribute hpack_decoder.
20 21 22 |
# File 'lib/plum/connection.rb', line 20 def hpack_decoder @hpack_decoder end |
#hpack_encoder ⇒ Object (readonly)
Returns the value of attribute hpack_encoder.
20 21 22 |
# File 'lib/plum/connection.rb', line 20 def hpack_encoder @hpack_encoder end |
#local_settings ⇒ Object (readonly)
Returns the value of attribute local_settings.
21 22 23 |
# File 'lib/plum/connection.rb', line 21 def local_settings @local_settings end |
#remote_settings ⇒ Object (readonly)
Returns the value of attribute remote_settings.
21 22 23 |
# File 'lib/plum/connection.rb', line 21 def remote_settings @remote_settings end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
22 23 24 |
# File 'lib/plum/connection.rb', line 22 def state @state end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
22 23 24 |
# File 'lib/plum/connection.rb', line 22 def streams @streams end |
Instance Method Details
#close ⇒ Object
Emits :close event. Doesn’t actually close socket.
41 42 43 44 |
# File 'lib/plum/connection.rb', line 41 def close # TODO: server MAY wait streams callback(:close) end |
#receive(new_data) ⇒ Object Also known as: <<
Receives the specified data and process.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plum/connection.rb', line 48 def receive(new_data) return if new_data.empty? @buffer << new_data negotiate! if @state == :negotiation if @state != :negotiation while frame = Frame.parse!(@buffer) callback(:frame, frame) receive_frame(frame) end end rescue ConnectionError => e callback(:connection_error, e) goaway(e.http2_error_type) close end |
#reserve_stream(**args) ⇒ Object
Reserves a new stream to server push.
69 70 71 72 73 |
# File 'lib/plum/connection.rb', line 69 def reserve_stream(**args) next_id = @max_even_stream_id + 2 stream = new_stream(next_id, state: :reserved_local, **args) stream end |