raptor 0.20.2 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,9 @@
1
1
  # Generated from lib/raptor/reactor.rb with RBS::Inline
2
2
 
3
3
  module Raptor
4
- # Multiplexes client connections and closes them when they overrun
5
- # their per-phase timeouts (first data, subsequent chunks, and
6
- # keep-alive idle). Feeds ready bytes to the parser pipeline and hands
7
- # completed requests back to the caller-provided handlers.
4
+ # Multiplexes client connections, manages connection deadlines, feeds
5
+ # ready bytes to the parser pipeline, and hands completed requests back
6
+ # to the caller-provided handlers.
8
7
  class Reactor
9
8
  # A client connection node ordered by absolute expiry time so the
10
9
  # soonest-to-expire is always at the tree's minimum.
@@ -38,27 +37,118 @@ module Raptor
38
37
  def <=>: (TimeoutClient other) -> Integer
39
38
  end
40
39
 
40
+ # Tracks reactor-owned output state for a connection.
41
+ class ConnectionIO
42
+ # @rbs attr_accessor offset: Integer
43
+ attr_accessor offset: untyped
44
+
45
+ # @rbs attr_accessor wait: Symbol?
46
+ attr_accessor wait: untyped
47
+
48
+ # @rbs attr_accessor reading: bool
49
+ attr_accessor reading: untyped
50
+
51
+ # @rbs attr_accessor closing: bool
52
+ attr_accessor closing: untyped
53
+
54
+ # @rbs attr_accessor monitor: NIO::Monitor?
55
+ attr_accessor monitor: untyped
56
+
57
+ # @rbs attr_accessor timeout: TimeoutClient?
58
+ attr_accessor timeout: untyped
59
+
60
+ # @rbs attr_reader output: Array[String]
61
+ attr_reader output: untyped
62
+
63
+ # @rbs () -> void
64
+ def initialize: () -> void
65
+
66
+ # @rbs () -> bool
67
+ def empty?: () -> bool
68
+ end
69
+
70
+ # Tracks reactor-owned I/O state for an HTTP/1.x detached response.
71
+ class Http1IO < ConnectionIO
72
+ # @rbs attr_accessor body: DetachedBody?
73
+ attr_accessor body: untyped
74
+
75
+ # @rbs attr_accessor finishing: bool
76
+ attr_accessor finishing: untyped
77
+
78
+ # @rbs attr_reader budget: DetachedBody::Budget
79
+ attr_reader budget: untyped
80
+
81
+ # @rbs attr_reader input: String
82
+ attr_reader input: untyped
83
+
84
+ # @rbs attr_reader state: Hash[Symbol, untyped]
85
+ attr_reader state: untyped
86
+
87
+ # @rbs (DetachedBody body, Hash[Symbol, untyped] state) -> void
88
+ def initialize: (DetachedBody body, Hash[Symbol, untyped] state) -> void
89
+
90
+ # @rbs () -> bool
91
+ def empty?: () -> bool
92
+ end
93
+
94
+ # Tracks reactor-owned I/O state for an HTTP/2 connection.
95
+ class Http2IO < ConnectionIO
96
+ # @rbs attr_reader detached: Hash[Integer, DetachedBody]
97
+ attr_reader detached: untyped
98
+
99
+ # @rbs attr_reader ready: Array[Integer]
100
+ attr_reader ready: untyped
101
+
102
+ # @rbs attr_reader ready_streams: Hash[Integer, bool]
103
+ attr_reader ready_streams: untyped
104
+
105
+ # @rbs attr_reader budget: DetachedBody::Budget
106
+ attr_reader budget: untyped
107
+
108
+ # @rbs () -> void
109
+ def initialize: () -> void
110
+
111
+ # @rbs () -> bool
112
+ def empty?: () -> bool
113
+ end
114
+
41
115
  CHUNK_SIZE: untyped
42
116
 
117
+ DETACHED_CONNECTION_BUFFER_SIZE: untyped
118
+
119
+ DETACHED_MAX_CHUNKS: ::Integer
120
+
121
+ DETACHED_MAX_FRAMES: ::Integer
122
+
123
+ DETACHED_WORKER_BUFFER_SIZE: untyped
124
+
43
125
  TIMEOUT_RESPONSE: ::String
44
126
 
45
- @thread_pool: untyped
127
+ @timeouts: RedBlackTree[TimeoutClient]
46
128
 
47
- @http1_ractor_pool: untyped
129
+ @io_queue: AtomicQueue
48
130
 
49
- @http2_ractor_pool: untyped
131
+ @queue: Queue[TCPSocket]
50
132
 
51
- @first_data_timeout: Integer
133
+ @selector: NIO::Selector
52
134
 
53
- @chunk_data_timeout: Integer
135
+ @http2_keepalive_timeout: Integer
136
+
137
+ @http2_keepalive_interval: Integer
138
+
139
+ @write_timeout: Integer
54
140
 
55
141
  @persistent_data_timeout: Integer
56
142
 
57
- @selector: NIO::Selector
143
+ @chunk_data_timeout: Integer
58
144
 
59
- @queue: Queue[TCPSocket]
145
+ @first_data_timeout: Integer
60
146
 
61
- @timeouts: RedBlackTree[TimeoutClient]
147
+ @http2_ractor_pool: untyped
148
+
149
+ @http1_ractor_pool: untyped
150
+
151
+ @thread_pool: untyped
62
152
 
63
153
  @id_to_socket: Hash[Integer, TCPSocket]
64
154
 
@@ -70,6 +160,22 @@ module Raptor
70
160
 
71
161
  @id_to_flow_control: Hash[Integer, untyped]
72
162
 
163
+ @id_to_http2_last_stream: Hash[Integer, Integer]
164
+
165
+ @id_to_http2_drain_stream: Hash[Integer, Integer]
166
+
167
+ @id_to_http2_keepalive: Hash[Integer, Hash[Symbol, untyped]]
168
+
169
+ @id_to_io: Hash[Integer, ConnectionIO]
170
+
171
+ @detached_budget: DetachedBody::Budget
172
+
173
+ @detached_count: Atom
174
+
175
+ @detached_drained: AtomicConditionVariable
176
+
177
+ @thread: Thread?
178
+
73
179
  # Creates a new Reactor instance.
74
180
  #
75
181
  # @param http1_ractor_pool [RactorPool] ractor pool for HTTP/1.x parsing
@@ -80,13 +186,16 @@ module Raptor
80
186
  # @option connection_options [Integer] :chunk_data_timeout timeout for subsequent chunks
81
187
  # @param http1_options [Hash] HTTP/1.1-specific configuration
82
188
  # @option http1_options [Integer] :persistent_data_timeout timeout for keep-alive idle connections
189
+ # @param http2_options [Hash] HTTP/2-specific configuration
190
+ # @option http2_options [Integer] :keepalive_interval idle time before sending a PING
191
+ # @option http2_options [Integer] :keepalive_timeout time to await a PING acknowledgement
83
192
  # @return [void]
84
193
  #
85
- # @rbs (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
86
- def initialize: (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
194
+ # @rbs (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped], http2_options: Hash[Symbol, untyped]) -> void
195
+ def initialize: (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped], http2_options: Hash[Symbol, untyped]) -> void
87
196
 
88
197
  # Starts the reactor's main event loop in a new thread. Runs until
89
- # the registration queue is closed and drained.
198
+ # shutdown work and pending writes are drained.
90
199
  #
91
200
  # @return [Thread] the thread running the reactor event loop
92
201
  #
@@ -162,6 +271,62 @@ module Raptor
162
271
  # @rbs (Integer id) -> untyped?
163
272
  def flow_control_for: (Integer id) -> untyped?
164
273
 
274
+ # Attaches a detached response body to an HTTP/1.x connection.
275
+ #
276
+ # @rbs (TCPSocket socket, Integer id, DetachedBody body, Hash[Symbol, untyped] state, ^(Symbol) -> void finished) -> bool
277
+ def attach_http1_body: (TCPSocket socket, Integer id, DetachedBody body, Hash[Symbol, untyped] state, ^(Symbol) -> void finished) -> bool
278
+
279
+ # Records an HTTP/2 stream before application dispatch, rejecting streams
280
+ # that arrived after graceful draining began.
281
+ #
282
+ # @param id [Integer] unique connection identifier
283
+ # @param stream_id [Integer] HTTP/2 stream identifier
284
+ # @return [Boolean] whether the stream may be dispatched
285
+ #
286
+ # @rbs (Integer id, Integer stream_id) -> bool
287
+ def dispatch_http2_stream: (Integer id, Integer stream_id) -> bool
288
+
289
+ # Sends GOAWAY on every HTTP/2 connection and fixes the last stream each
290
+ # connection may dispatch while existing application work drains.
291
+ #
292
+ # @yieldparam stream_id [Integer] last dispatched stream identifier
293
+ # @yieldreturn [String] serialized GOAWAY frame
294
+ # @return [void]
295
+ #
296
+ # @rbs () { (Integer stream_id) -> String } -> void
297
+ def drain_http2: () { (Integer stream_id) -> String } -> void
298
+
299
+ # Queues serialized HTTP/2 frames for a connection. Producers never
300
+ # write to the socket or wait for it to become writable.
301
+ #
302
+ # @param id [Integer] unique connection identifier
303
+ # @param frames [Array<String>] frame bytes to write in order
304
+ # @return [void]
305
+ #
306
+ # @rbs (Integer id, Array[String] frames) -> void
307
+ def write_http2_frames: (Integer id, Array[String] frames) -> void
308
+
309
+ # Attaches a detached response body to an HTTP/2 stream.
310
+ #
311
+ # @rbs (Integer id, Integer stream_id, DetachedBody body, ^(Symbol) -> void finished) -> bool
312
+ def attach_http2_body: (Integer id, Integer stream_id, DetachedBody body, ^(Symbol) -> void finished) -> bool
313
+
314
+ # Reconsiders detached streams after an outbound window update.
315
+ #
316
+ # @rbs (Integer id) -> void
317
+ def resume_http2_bodies: (Integer id) -> void
318
+
319
+ # Cancels a detached response stream.
320
+ #
321
+ # @rbs (Integer id, Integer stream_id) -> void
322
+ def cancel_http2_body: (Integer id, Integer stream_id) -> void
323
+
324
+ # Waits for detached responses to finish, then cancels any that outlive
325
+ # the worker drain period.
326
+ #
327
+ # @rbs (Numeric timeout) -> void
328
+ def drain_detached_bodies: (Numeric timeout) -> void
329
+
165
330
  # Stores an HTTP/2 connection's socket, state, writer, and flow
166
331
  # controller in the reactor's per-connection maps.
167
332
  #
@@ -170,10 +335,21 @@ module Raptor
170
335
  # @param state [Hash] initial connection state
171
336
  # @param writer [Http2::Writer] per-connection frame writer
172
337
  # @param flow_control [Http2::FlowControl] per-connection outbound flow controller
338
+ # @param ping_frame [String] serialized PING frame for keepalive probes
339
+ # @param ping_payload [String] payload expected in the corresponding acknowledgement
340
+ # @return [void]
341
+ #
342
+ # @rbs (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped, ping_frame: String, ping_payload: String) -> void
343
+ def attach_http2: (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped, ping_frame: String, ping_payload: String) -> void
344
+
345
+ # Records acknowledgements for server keepalive probes.
346
+ #
347
+ # @param id [Integer] unique connection identifier
348
+ # @param payloads [Array<String>, nil] acknowledged PING payloads
173
349
  # @return [void]
174
350
  #
175
- # @rbs (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped) -> void
176
- def attach_http2: (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped) -> void
351
+ # @rbs (Integer id, Array[String]? payloads) -> void
352
+ def acknowledge_http2_ping: (Integer id, Array[String]? payloads) -> void
177
353
 
178
354
  # Registers an attached socket for future reactor-driven reads.
179
355
  #
@@ -192,8 +368,7 @@ module Raptor
192
368
  # @rbs (Hash[Symbol, untyped] state) -> void
193
369
  def update_http2_state: (Hash[Symbol, untyped] state) -> void
194
370
 
195
- # Closes the socket for the given connection and drops all reactor
196
- # state associated with it.
371
+ # Closes a connection after writing any frames already queued for it.
197
372
  #
198
373
  # @param id [Integer] unique client identifier
199
374
  # @return [void]
@@ -219,6 +394,167 @@ module Raptor
219
394
 
220
395
  private
221
396
 
397
+ # Returns whether shutdown has no registrations or writes left to drain.
398
+ #
399
+ # @return [Boolean]
400
+ #
401
+ # @rbs () -> bool
402
+ def stopped?: () -> bool
403
+
404
+ # Handles every expired connection deadline in order.
405
+ #
406
+ # @param now [Float] current monotonic timestamp
407
+ # @return [void]
408
+ #
409
+ # @rbs (Float now) -> void
410
+ def expire_timeouts: (Float now) -> void
411
+
412
+ # Applies queued reactor-owned I/O operations.
413
+ #
414
+ # @return [void]
415
+ #
416
+ # @rbs () -> void
417
+ def drain_io_queue: () -> void
418
+
419
+ # Adds a detached body to an HTTP/1.x connection.
420
+ #
421
+ # @rbs (TCPSocket socket, Integer id, DetachedBody body, Hash[Symbol, untyped] state, ^(Symbol) -> void finished) -> void
422
+ def attach_http1_detached_body: (TCPSocket socket, Integer id, DetachedBody body, Hash[Symbol, untyped] state, ^(Symbol) -> void finished) -> void
423
+
424
+ # Writes buffered HTTP/1.x body chunks without blocking.
425
+ #
426
+ # @rbs (Integer id) -> void
427
+ def flush_http1_detached_body: (Integer id) -> void
428
+
429
+ # Finishes an HTTP/1.x detached response and either reuses or closes its connection.
430
+ #
431
+ # @rbs (Integer id, Http1IO io) -> void
432
+ def finish_http1_detached_body: (Integer id, Http1IO io) -> void
433
+
434
+ # Cancels an HTTP/1.x detached response and closes its connection.
435
+ #
436
+ # @rbs (Integer id, Symbol reason) -> void
437
+ def remove_http1_detached_body: (Integer id, Symbol reason) -> void
438
+
439
+ # Adds a detached body to an HTTP/2 stream.
440
+ #
441
+ # @rbs (Integer id, Integer stream_id, DetachedBody body, ^(Symbol) -> void finished) -> void
442
+ def attach_http2_detached_body: (Integer id, Integer stream_id, DetachedBody body, ^(Symbol) -> void finished) -> void
443
+
444
+ # Marks an HTTP/2 detached stream eligible for fair scheduling.
445
+ #
446
+ # @rbs (Integer id, Integer stream_id) -> void
447
+ def mark_http2_detached_body_ready: (Integer id, Integer stream_id) -> void
448
+
449
+ # Marks every HTTP/2 detached stream eligible after flow-control capacity changes.
450
+ #
451
+ # @rbs (Integer id) -> void
452
+ def resume_http2_detached_bodies: (Integer id) -> void
453
+
454
+ # Writes HTTP/2 detached streams in round-robin order without waiting for flow control.
455
+ #
456
+ # @rbs (Integer id) -> void
457
+ def flush_http2_detached_bodies: (Integer id) -> void
458
+
459
+ # Finishes an HTTP/2 detached stream with DATA or trailing HEADERS.
460
+ #
461
+ # @rbs (Integer id, Integer stream_id, DetachedBody body) -> void
462
+ def finish_http2_detached_body: (Integer id, Integer stream_id, DetachedBody body) -> void
463
+
464
+ # Removes an HTTP/2 detached stream and schedules its close callback.
465
+ #
466
+ # @rbs (Integer id, Integer stream_id, Symbol reason) -> void
467
+ def remove_http2_detached_body: (Integer id, Integer stream_id, Symbol reason) -> void
468
+
469
+ # Cancels every detached response during worker shutdown.
470
+ #
471
+ # @rbs () -> void
472
+ def cancel_detached_bodies: () -> void
473
+
474
+ # Records one detached stream finishing.
475
+ #
476
+ # @rbs () -> void
477
+ def detached_body_removed: () -> void
478
+
479
+ # Closes a connection once its queued frames are written.
480
+ #
481
+ # @param id [Integer] unique client identifier
482
+ # @return [void]
483
+ #
484
+ # @rbs (Integer id) -> void
485
+ def close_after_writes: (Integer id) -> void
486
+
487
+ # Immediately closes a connection and drops its reactor state.
488
+ #
489
+ # @param id [Integer] unique client identifier
490
+ # @return [void]
491
+ #
492
+ # @rbs (Integer id) -> void
493
+ def remove_connection: (Integer id) -> void
494
+
495
+ # Adds bytes to one connection and writes as much as the socket accepts.
496
+ #
497
+ # @param io [ConnectionIO] connection I/O state
498
+ # @param data [String] serialized response bytes
499
+ # @return [void]
500
+ #
501
+ # @rbs (ConnectionIO? io, String data) -> void
502
+ def queue_output: (ConnectionIO? io, String data) -> void
503
+
504
+ # Drains one connection's queued response bytes without blocking.
505
+ #
506
+ # @param id [Integer] unique connection identifier
507
+ # @param io [ConnectionIO] connection I/O state
508
+ # @return [void]
509
+ #
510
+ # @rbs (Integer id, ConnectionIO? io) -> void
511
+ def flush_output: (Integer id, ConnectionIO? io) -> void
512
+
513
+ # Registers the readiness needed to continue a partial socket write.
514
+ #
515
+ # @param id [Integer] unique connection identifier
516
+ # @param io [ConnectionIO] connection I/O state
517
+ # @param readiness [Symbol] `:read` or `:write`
518
+ # @return [void]
519
+ #
520
+ # @rbs (Integer id, ConnectionIO io, Symbol readiness) -> void
521
+ def wait_for_write: (Integer id, ConnectionIO io, Symbol readiness) -> void
522
+
523
+ # Updates selector interest for one reactor-owned connection.
524
+ #
525
+ # @param id [Integer] unique connection identifier
526
+ # @param io [ConnectionIO] connection I/O state
527
+ # @return [void]
528
+ #
529
+ # @rbs (Integer id, ConnectionIO io) -> void
530
+ def update_monitor: (Integer id, ConnectionIO io) -> void
531
+
532
+ # Starts or refreshes one connection's non-blocking write deadline.
533
+ #
534
+ # @param id [Integer] unique connection identifier
535
+ # @param io [ConnectionIO] connection I/O state
536
+ # @return [void]
537
+ #
538
+ # @rbs (Integer id, ConnectionIO io) -> void
539
+ def track_write_timeout: (Integer id, ConnectionIO io) -> void
540
+
541
+ # Removes one connection's non-blocking write deadline.
542
+ #
543
+ # @param io [ConnectionIO, nil] connection I/O state
544
+ # @return [void]
545
+ #
546
+ # @rbs (ConnectionIO? io) -> void
547
+ def clear_write_timeout: (ConnectionIO? io) -> void
548
+
549
+ # Removes a socket from selector tracking.
550
+ #
551
+ # @param socket [TCPSocket] socket to deregister
552
+ # @param io [ConnectionIO, nil] connection I/O state
553
+ # @return [void]
554
+ #
555
+ # @rbs (TCPSocket socket, ConnectionIO? io) -> void
556
+ def deregister: (TCPSocket socket, ConnectionIO? io) -> void
557
+
222
558
  # Registers a socket with the NIO selector and sets up timeout tracking.
223
559
  #
224
560
  # @param socket [TCPSocket] the socket to register
@@ -227,6 +563,39 @@ module Raptor
227
563
  # @rbs (TCPSocket socket) -> void
228
564
  def register: (TCPSocket socket) -> void
229
565
 
566
+ # Adds a connection deadline to the timeout tree.
567
+ #
568
+ # @param state [Hash] client connection state
569
+ # @param timeout_at [Float] absolute monotonic expiry time
570
+ # @return [void]
571
+ #
572
+ # @rbs (Hash[Symbol, untyped] state, Float timeout_at) -> void
573
+ def track_timeout: (Hash[Symbol, untyped] state, Float timeout_at) -> void
574
+
575
+ # Handles an expired connection deadline, sending an HTTP/2 keepalive
576
+ # probe before closing the connection when its acknowledgement is late.
577
+ #
578
+ # @param client [TimeoutClient] expired client
579
+ # @param now [Float] current monotonic timestamp
580
+ # @return [void]
581
+ #
582
+ # @rbs (TimeoutClient client, Float now) -> void
583
+ def handle_timeout: (TimeoutClient client, Float now) -> void
584
+
585
+ # Dispatches readable and writable events without allowing application
586
+ # threads to take ownership of HTTP/2 sockets.
587
+ #
588
+ # @param monitor [NIO::Monitor] ready selector monitor
589
+ # @return [void]
590
+ #
591
+ # @rbs (NIO::Monitor monitor) -> void
592
+ def handle_monitor: (NIO::Monitor monitor) -> void
593
+
594
+ # Handles readiness for an HTTP/1.x detached response.
595
+ #
596
+ # @rbs (NIO::Monitor monitor, Integer id) -> void
597
+ def handle_http1_detached_monitor: (NIO::Monitor monitor, Integer id) -> void
598
+
230
599
  # Handles socket wakeup by deregistering and queuing for processing.
231
600
  #
232
601
  # @param socket [TCPSocket] the socket that became ready
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young
@@ -158,6 +158,7 @@ files:
158
158
  - lib/raptor/cli.rb
159
159
  - lib/raptor/cluster.rb
160
160
  - lib/raptor/control_server.rb
161
+ - lib/raptor/detached_body.rb
161
162
  - lib/raptor/http.rb
162
163
  - lib/raptor/http1.rb
163
164
  - lib/raptor/http2.rb
@@ -175,6 +176,7 @@ files:
175
176
  - sig/generated/raptor/cli.rbs
176
177
  - sig/generated/raptor/cluster.rbs
177
178
  - sig/generated/raptor/control_server.rbs
179
+ - sig/generated/raptor/detached_body.rbs
178
180
  - sig/generated/raptor/http.rbs
179
181
  - sig/generated/raptor/http1.rbs
180
182
  - sig/generated/raptor/http2.rbs
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
208
  - !ruby/object:Gem::Version
207
209
  version: '0'
208
210
  requirements: []
209
- rubygems_version: 4.0.16
211
+ rubygems_version: 4.0.20
210
212
  specification_version: 4
211
213
  summary: "A high-performance Ruby web server (rawr \U0001F996)"
212
214
  test_files: []