protocol-http2 0.9.7 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 585d6a3435b1d498dc310e46ca8f52fd8e1cd37471409b8c9da6cf2f467aaa69
4
- data.tar.gz: d1d1d8cbf77af69ff83d112bafe79fbf786ad24552a03e8af96bfcfeedf9752a
3
+ metadata.gz: 65e32ccd867aeb59ecc2f549fd376faf912662e9dc13013fb96631e0f1a818e9
4
+ data.tar.gz: d5cea11e3665707f1e1e187c2d38661615d5731bbf37253c1ff020b581364c8d
5
5
  SHA512:
6
- metadata.gz: bb7a4bc6c1eb7f0c26ce9fc570aa2cfe5879114c5bf305a6abb8cd20171a31d142c597ac33c28994c3740f4df84ba2a0f5efe7529c8bd1ae7272084fba3a4a44
7
- data.tar.gz: effc253ab1ddf6b60f8a8cc152cdc73b6be3c07c7e09bd5a0dd0bcb81856fddbd5c35ca0ee88a8c7c8a280738789c81c700dac8ebfdc70be5159e0e98f0b292a
6
+ metadata.gz: d54116953f0ecab132997502fdc8a53f0df18865372773bf1edc5db393a922c60c49b7a46c0deaff3702a6bf57e244316396424081d15efa0350421fa8cd55c9
7
+ data.tar.gz: e45da44d211b8ff2b37c094fb5674e3fb508681a897931b1786db96413665bc6182140986c289f6a6dd0ab38225348f5ab6adb0a2c0c0bd403d95bfc7a5d3173
@@ -35,6 +35,8 @@ module Protocol
35
35
  @streams = {}
36
36
  @children = {}
37
37
 
38
+ @active = 0
39
+
38
40
  @framer = framer
39
41
  @local_stream_id = local_stream_id
40
42
  @remote_stream_id = 0
@@ -97,9 +99,19 @@ module Protocol
97
99
  @state == :closed
98
100
  end
99
101
 
102
+ # The stream has become active (i.e. not idle or closed).
103
+ def activate(stream)
104
+ @active += 1
105
+ end
106
+
107
+ # The stream is no longer active (i.e. has become closed).
108
+ def deactivate(stream)
109
+ @active -= 1
110
+ end
111
+
112
+ # The number of active streams.
100
113
  def active_streams
101
- # TODO inefficient
102
- @streams.each_value.select(&:active?)
114
+ @active
103
115
  end
104
116
 
105
117
  # Close the underlying framer and all streams.
@@ -103,6 +103,7 @@ module Protocol
103
103
  end
104
104
 
105
105
  # Traverse active streams in order of priority and allow them to consume the available flow-control window.
106
+ # @todo This function can get slow when there are a lot of children [INEFFICIENT].
106
107
  # @param amount [Integer] the amount of data to write. Defaults to the current window capacity.
107
108
  def consume_window(size = self.available_size)
108
109
  # Don't consume more than the available window size:
@@ -120,6 +120,10 @@ module Protocol
120
120
 
121
121
  @state = state
122
122
 
123
+ if active?
124
+ connnection.active(self)
125
+ end
126
+
123
127
  # Stream priority:
124
128
  @dependent_id = dependent_id
125
129
  @weight = weight
@@ -309,7 +313,12 @@ module Protocol
309
313
  end
310
314
 
311
315
  def open!
312
- @state = :open
316
+ if @state == :idle
317
+ @state = :open
318
+ @connection.activate(self)
319
+ else
320
+ raise ProtocolError, "Cannot open stream in state: #{@state}"
321
+ end
313
322
 
314
323
  return self
315
324
  end
@@ -319,6 +328,9 @@ module Protocol
319
328
  def close!(error_code = nil)
320
329
  @state = :closed
321
330
 
331
+ @connection.deactivate(self)
332
+ self.parent&.remove_child(self)
333
+
322
334
  if error_code
323
335
  error = StreamError.new("Stream closed!", error_code)
324
336
  end
@@ -481,6 +493,7 @@ module Protocol
481
493
  def reserved_local!
482
494
  if @state == :idle
483
495
  @state = :reserved_local
496
+ @connection.activate(self)
484
497
  else
485
498
  raise ProtocolError, "Cannot reserve stream in state: #{@state}"
486
499
  end
@@ -489,6 +502,7 @@ module Protocol
489
502
  def reserved_remote!
490
503
  if @state == :idle
491
504
  @state = :reserved_remote
505
+ @connection.activate(self)
492
506
  else
493
507
  raise ProtocolError, "Cannot reserve stream in state: #{@state}"
494
508
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module HTTP2
23
- VERSION = "0.9.7"
23
+ VERSION = "0.10.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams