Coverage Report

Created: 2026-11-11 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/proxy/http2/Http2ConnectionState.h
Line
Count
Source
1
/** @file
2
3
  Http2ConnectionState.
4
5
  @par License
6
7
  Licensed to the Apache Software Foundation (ASF) under one
8
  or more contributor license agreements.  See the NOTICE file
9
  distributed with this work for additional information
10
  regarding copyright ownership.  The ASF licenses this file
11
  to you under the Apache License, Version 2.0 (the
12
  "License"); you may not use this file except in compliance
13
  with the License.  You may obtain a copy of the License at
14
15
      http://www.apache.org/licenses/LICENSE-2.0
16
17
  Unless required by applicable law or agreed to in writing, software
18
  distributed under the License is distributed on an "AS IS" BASIS,
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
  See the License for the specific language governing permissions and
21
  limitations under the License.
22
 */
23
24
#pragma once
25
26
#include <atomic>
27
#include <queue>
28
29
#include "iocore/net/NetTimeout.h"
30
31
#include "proxy/http2/HTTP2.h"
32
#include "proxy/http2/HPACK.h"
33
#include "proxy/http2/Http2Stream.h"
34
#include "proxy/http2/Http2DependencyTree.h"
35
#include "tscore/FrequencyCounter.h"
36
37
class Http2CommonSession;
38
class Http2Frame;
39
40
enum class Http2SendDataFrameResult {
41
  NO_ERROR = 0,
42
  NO_WINDOW,
43
  NO_PAYLOAD,
44
  NOT_WRITE_AVAIL,
45
  ERROR,
46
  DONE,
47
};
48
49
enum Http2ShutdownState { HTTP2_SHUTDOWN_NONE, HTTP2_SHUTDOWN_NOT_INITIATED, HTTP2_SHUTDOWN_INITIATED, HTTP2_SHUTDOWN_IN_PROGRESS };
50
51
class Http2ConnectionSettings
52
{
53
public:
54
  Http2ConnectionSettings();
55
56
  void     settings_from_configs(bool is_outbound);
57
  unsigned get(Http2SettingsIdentifier id) const;
58
  unsigned set(Http2SettingsIdentifier id, unsigned value);
59
60
private:
61
  // Settings ID is 1-based, so convert it to a 0-based index.
62
  static unsigned indexof(Http2SettingsIdentifier id);
63
64
  unsigned settings[HTTP2_SETTINGS_MAX - 1];
65
};
66
67
// Http2ConnectionState
68
//
69
// Capture the semantics of a HTTP/2 connection. The client session captures the
70
// frame layer, and the
71
// connection state captures the connection-wide state.
72
73
class Http2ConnectionState : public Continuation
74
{
75
public:
76
  Http2ConnectionState();
77
78
  // noncopyable
79
  Http2ConnectionState(const Http2ConnectionState &)            = delete;
80
  Http2ConnectionState &operator=(const Http2ConnectionState &) = delete;
81
82
  ProxyError               rx_error_code;
83
  ProxyError               tx_error_code;
84
  Http2CommonSession      *session            = nullptr;
85
  HpackHandle             *local_hpack_handle = nullptr;
86
  HpackHandle             *peer_hpack_handle  = nullptr;
87
  DependencyTree          *dependency_tree    = nullptr;
88
  ActivityCop<Http2Stream> _cop;
89
90
  /** The HTTP/2 settings configured by ATS and dictated to the peer via
91
   * SETTINGS frames. */
92
  Http2ConnectionSettings local_settings;
93
94
  /** The latest set of settings that have been acknowledged by the peer.
95
   *
96
   * The default constructed value of this via the Http2ConnectionSettings
97
   * constructor (i.e., the value before any SETTINGS ACK frames have been
98
   * received) will instantiate these settings to the default HTTP/2 settings
99
   * values.
100
   *
101
   * @note that @a local_settings are our latest configured settings which have
102
   * been sent to the peer but may not be acknowledged yet. @a
103
   * last_acknowledged_settings are the latest settings of which the peer has
104
   * acknowledged receipt. For this reason, window enforcement behavior and
105
   * WINDOW_UPDATE calculations should be based upon @a
106
   * last_acknowledged_settings.
107
   */
108
  Http2ConnectionSettings acknowledged_local_settings;
109
110
  /** The HTTP/2 settings configured by the peer and dictated to ATS via
111
   * SETTINGS frames. */
112
  Http2ConnectionSettings peer_settings;
113
114
  void init(Http2CommonSession *ssn);
115
  void send_connection_preface();
116
  void destroy();
117
  void rcv_frame(const Http2Frame *frame);
118
119
  // Event handlers
120
  int main_event_handler(int, void *);
121
  int state_closed(int, void *);
122
123
  // Stream control interfaces
124
  Http2Stream *create_stream(Http2StreamId new_id, Http2Error &error);
125
  Http2Stream *create_initiating_stream(Http2Error &error);
126
  void         set_stream_id(Http2Stream *stream);
127
  Http2Stream *find_stream(Http2StreamId id) const;
128
  void         restart_streams();
129
  bool         delete_stream(Http2Stream *stream);
130
  void         release_stream();
131
  void         cleanup_streams();
132
  void         restart_receiving(Http2Stream *stream);
133
134
  /** Update all streams for the peer's newly dictated stream window size. */
135
  void update_initial_peer_rwnd(Http2WindowSize new_size);
136
137
  /** Update all streams for our newly dictated stream window size. */
138
  void update_initial_local_rwnd(Http2WindowSize new_size);
139
140
  Http2StreamId get_latest_stream_id_in() const;
141
  Http2StreamId get_latest_stream_id_out() const;
142
  int           get_stream_requests() const;
143
  void          increment_stream_requests();
144
  bool          is_peer_concurrent_stream_ub() const;
145
  bool          is_peer_concurrent_stream_lb() const;
146
147
  // Continuated header decoding
148
  Http2StreamId get_continued_stream_id() const;
149
  void          set_continued_stream_id(Http2StreamId stream_id);
150
  void          clear_continued_stream_id();
151
152
  uint32_t       get_peer_stream_count() const;
153
  void           decrement_peer_stream_count();
154
  double         get_stream_error_rate() const;
155
  Http2ErrorCode get_shutdown_reason() const;
156
157
  // HTTP/2 frame sender
158
  void                     schedule_stream_to_send_priority_frames(Http2Stream *stream);
159
  void                     send_data_frames_depends_on_priority();
160
  void                     schedule_stream_to_send_data_frames(Http2Stream *stream);
161
  void                     schedule_retransmit(ink_hrtime t);
162
  void                     cancel_retransmit();
163
  void                     send_data_frames(Http2Stream *stream);
164
  Http2SendDataFrameResult send_a_data_frame(Http2Stream *stream, size_t &payload_length);
165
  void                     send_headers_frame(Http2Stream *stream);
166
  bool                     send_push_promise_frame(Http2Stream *stream, URL &url, const MIMEField *accept_encoding);
167
  void                     send_rst_stream_frame(Http2StreamId id, Http2ErrorCode ec);
168
169
  static constexpr bool SEND_EMPTY = true;
170
171
  /** Send a SETTINGS frame to the peer.
172
   *
173
   * local_settings is updated to the value of @a new_settings as a byproduct
174
   * of this call.
175
   *
176
   * @param[in] new_settings The settings to send to the peer.
177
   * @param[in] send_empty Whether to send a SETTINGS frame if @a new_settings
178
   * has no changes from the current local settings.
179
   * @return The result of sending the SETTINGS frame.
180
   */
181
  Http2Error send_settings_frame(const Http2ConnectionSettings &new_settings, bool send_empty);
182
183
  void send_ping_frame(Http2StreamId id, uint8_t flag, const uint8_t *opaque_data);
184
  void send_goaway_frame(Http2StreamId id, Http2ErrorCode ec);
185
  void send_window_update_frame(Http2StreamId id, uint32_t size);
186
187
  bool is_state_closed() const;
188
  bool is_recursing() const;
189
  bool is_valid_streamid(Http2StreamId id) const;
190
191
  Http2ShutdownState get_shutdown_state() const;
192
  void               set_shutdown_state(Http2ShutdownState state, Http2ErrorCode reason = Http2ErrorCode::HTTP2_ERROR_NO_ERROR);
193
194
  Event *get_zombie_event();
195
  void   schedule_zombie_event();
196
197
  void     increment_received_settings_count(uint32_t count);
198
  uint32_t get_received_settings_count();
199
  void     increment_received_settings_frame_count();
200
  uint32_t get_received_settings_frame_count();
201
  void     increment_received_ping_frame_count();
202
  uint32_t get_received_ping_frame_count();
203
  void     increment_received_priority_frame_count();
204
  uint32_t get_received_priority_frame_count();
205
  void     increment_received_rst_stream_frame_count();
206
  uint32_t get_received_rst_stream_frame_count();
207
  void     increment_received_continuation_frame_count();
208
  uint32_t get_received_continuation_frame_count();
209
  void     increment_received_empty_frame_count();
210
  uint32_t get_received_empty_frame_count();
211
212
  ssize_t        get_peer_rwnd() const;
213
  Http2ErrorCode increment_peer_rwnd(size_t amount);
214
  Http2ErrorCode decrement_peer_rwnd(size_t amount);
215
  ssize_t        get_local_rwnd() const;
216
  Http2ErrorCode increment_local_rwnd(size_t amount);
217
  Http2ErrorCode decrement_local_rwnd(size_t amount);
218
219
  bool no_streams() const;
220
  bool single_stream() const;
221
222
private:
223
  Http2Error rcv_data_frame(const Http2Frame &);
224
  Http2Error rcv_headers_frame(const Http2Frame &);
225
  Http2Error rcv_priority_frame(const Http2Frame &);
226
  Http2Error rcv_rst_stream_frame(const Http2Frame &);
227
  Http2Error rcv_settings_frame(const Http2Frame &);
228
  Http2Error rcv_push_promise_frame(const Http2Frame &);
229
  Http2Error rcv_ping_frame(const Http2Frame &);
230
  Http2Error rcv_goaway_frame(const Http2Frame &);
231
  Http2Error rcv_window_update_frame(const Http2Frame &);
232
  Http2Error rcv_continuation_frame(const Http2Frame &);
233
234
  using http2_frame_dispatch = Http2Error (Http2ConnectionState::*)(const Http2Frame &);
235
  static constexpr http2_frame_dispatch _frame_handlers[HTTP2_FRAME_TYPE_MAX] = {
236
    &Http2ConnectionState::rcv_data_frame,          // HTTP2_FRAME_TYPE_DATA
237
    &Http2ConnectionState::rcv_headers_frame,       // HTTP2_FRAME_TYPE_HEADERS
238
    &Http2ConnectionState::rcv_priority_frame,      // HTTP2_FRAME_TYPE_PRIORITY
239
    &Http2ConnectionState::rcv_rst_stream_frame,    // HTTP2_FRAME_TYPE_RST_STREAM
240
    &Http2ConnectionState::rcv_settings_frame,      // HTTP2_FRAME_TYPE_SETTINGS
241
    &Http2ConnectionState::rcv_push_promise_frame,  // HTTP2_FRAME_TYPE_PUSH_PROMISE
242
    &Http2ConnectionState::rcv_ping_frame,          // HTTP2_FRAME_TYPE_PING
243
    &Http2ConnectionState::rcv_goaway_frame,        // HTTP2_FRAME_TYPE_GOAWAY
244
    &Http2ConnectionState::rcv_window_update_frame, // HTTP2_FRAME_TYPE_WINDOW_UPDATE
245
    &Http2ConnectionState::rcv_continuation_frame,  // HTTP2_FRAME_TYPE_CONTINUATION
246
  };
247
248
  unsigned _adjust_concurrent_stream();
249
250
  /** Top up the connection receive window after discarding a DATA frame.
251
   *
252
   * DATA that no stream will consume is still charged to the connection
253
   * window, so nothing else would trigger a WINDOW_UPDATE for it. This tops
254
   * the window back up to its configured size via restart_receiving() once it
255
   * falls below the usual threshold.
256
   *
257
   * @param[in] discarded_length The discarded frame's payload length, used
258
   *   only for debug logging.
259
   */
260
  void _top_up_window_after_discard(uint32_t discarded_length);
261
262
  /** Process an incoming SETTINGS ACK frame.
263
   *
264
   * Applies the settings from the front of the outstanding settings queue,
265
   * updating acknowledged_local_settings and adjusting stream receive
266
   * windows if INITIAL_WINDOW_SIZE changed.
267
   *
268
   * @return The result of processing the SETTINGS ACK.
269
   */
270
  Http2Error _process_incoming_settings_ack_frame();
271
272
  /** Check whether new settings differ from current local settings.
273
   *
274
   * This determines whether @a new_settings would require sending a non-empty
275
   * SETTINGS frame, giving frame-suppression and outstanding-frame limit
276
   * checks a shared definition of a settings change.
277
   *
278
   * @param[in] new_settings The candidate settings to compare.
279
   * @return @c true if any emitted setting differs from current local
280
   * settings.
281
   */
282
  bool _settings_have_changes(const Http2ConnectionSettings &new_settings) const;
283
284
  /** Check whether a SETTINGS frame can be sent without exceeding local debt.
285
   *
286
   * A SETTINGS frame that would carry no settings and is not required to be
287
   * sent is treated as sendable because it will be skipped.
288
   *
289
   * @param[in] new_settings The settings to send to the peer.
290
   * @param[in] send_empty Whether to send an empty SETTINGS frame.
291
   * @return The result of checking whether the SETTINGS frame can be sent.
292
   */
293
  Http2Error _check_outgoing_settings_frame(const Http2ConnectionSettings &new_settings, bool send_empty) const;
294
295
  /** Calculate the maximum SETTINGS frames that can await peer ACKs.
296
   *
297
   * The limit bounds the memory used to retain local settings snapshots while
298
   * still allowing the connection preface and one full concurrent-stream wave
299
   * of dynamic stream window updates.
300
   *
301
   * @return The number of outstanding SETTINGS frames allowed on this
302
   * connection.
303
   */
304
  size_t _get_outstanding_settings_frame_limit() const;
305
306
  /** Signal a connection-level HTTP/2 error and schedule session shutdown.
307
   *
308
   * This sends GOAWAY once, marks the session half-closed locally so no new
309
   * streams are accepted, and schedules finalization if it is not already
310
   * pending.
311
   *
312
   * @param[in] error_code The HTTP/2 error code to send in GOAWAY.
313
   */
314
  void _close_connection(Http2ErrorCode error_code);
315
316
  Http2FlowControlPolicy _flow_control_policy{
317
    Http2FlowControlPolicy::STATIC_SESSION_AND_STATIC_STREAM}; ///< Policy at connection initialization.
318
319
  // Getters for stream control configurations that retrieve the inbound or
320
  // outbound values per the configured session.
321
  uint32_t               _get_configured_max_concurrent_streams() const;
322
  uint32_t               _get_configured_min_concurrent_streams() const;
323
  uint32_t               _get_configured_max_active_streams() const;
324
  uint32_t               _get_configured_initial_window_size() const;
325
  Http2FlowControlPolicy _get_configured_flow_control_policy() const;
326
327
  /** Calculate the initial session window size that we communicate to inbound
328
   * peers.
329
   *
330
   * @return The initial receive window size.
331
   */
332
  uint32_t _get_configured_receive_session_window_size() const;
333
334
  /** Whether the stream window can change over the lifetime of a session.
335
   *
336
   * @return @c true if the stream window can change, @c false otherwise.
337
   */
338
  bool _has_dynamic_stream_window() const;
339
340
  // NOTE: 'stream_list' has only active streams.
341
  //   If given Stream Identifier is not found in stream_list and it is less
342
  //   than or equal to latest_streamid_in, the state of Stream
343
  //   is CLOSED.
344
  //   If given Stream Identifier is not found in stream_list and it is greater
345
  //   than latest_streamid_in, the state of Stream is IDLE.
346
  Queue<Http2Stream> stream_list;
347
  Http2StreamId      latest_streamid_in  = 0;
348
  Http2StreamId      latest_streamid_out = 0;
349
  std::atomic<int>   stream_requests     = 0;
350
351
  // Counter for current active streams which are started by the client.
352
  std::atomic<uint32_t> peer_streams_count_in = 0;
353
354
  // Counter for current active streams which are started by the origin.
355
  std::atomic<uint32_t> peer_streams_count_out = 0;
356
357
  // Counter for current active streams (from either the client or origin side)
358
  // and streams in the process of shutting down
359
  std::atomic<uint32_t> total_peer_streams_count = 0;
360
361
  // Counter for stream errors ATS sent
362
  uint32_t stream_error_count = 0;
363
364
  // Connection level window size
365
366
  /** The session level window that we have to respect when we send data to the
367
   * peer.
368
   *
369
   * This is the session window configured by the peer via WINDOW_UPDATE
370
   * frames. Per specification, this defaults to HTTP2_INITIAL_WINDOW_SIZE (see
371
   * RFC 9113, section 6.9.2). As we send data, we decrement this value. If it
372
   * reaches zero, we stop sending data to respect the peer's flow control
373
   * specification. When we receive WINDOW_UPDATE frames, we increment this
374
   * value.
375
   */
376
  ssize_t _peer_rwnd = HTTP2_INITIAL_WINDOW_SIZE;
377
378
  /** The session window we maintain with the peer via WINDOW_UPDATE frames.
379
   *
380
   * We maintain the window we expect the peer to respect by sending
381
   * WINDOW_UPDATE frames to the peer. As we receive data, we decrement this
382
   * value, as we send WINDOW_UPDATE frames, we increment it. If it reaches
383
   * zero, we generate a connection-level error.
384
   */
385
  ssize_t _local_rwnd = 0;
386
387
  /** Whether the client-side session window is in a shrinking state before we
388
   * send the first WINDOW_UPDATE frame.
389
   *
390
   * Unlike HTTP/2 streams, the HTTP/2 session window has no way to initialize
391
   * it to a value lower than 65,535. If the initial value is lower than
392
   * 65,535, the session window will have to shrink while we receive DATA
393
   * frames without incrementing the window via WINDOW_UPDATE frames. Once the
394
   * window gets to the desired size, we start maintaining the window via
395
   * WINDOW_UPDATE frames.
396
   */
397
  bool _local_rwnd_is_shrinking = false;
398
399
  std::array<size_t, 5> _recent_rwnd_increment       = {SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX};
400
  int                   _recent_rwnd_increment_index = 0;
401
402
  FrequencyCounter _received_settings_counter;
403
  FrequencyCounter _received_settings_frame_counter;
404
  FrequencyCounter _received_ping_frame_counter;
405
  FrequencyCounter _received_priority_frame_counter;
406
  FrequencyCounter _received_rst_stream_frame_counter;
407
  FrequencyCounter _received_continuation_frame_counter;
408
  FrequencyCounter _received_empty_frame_counter;
409
410
  /** Records the various settings for each SETTINGS frame that we've sent.
411
   *
412
   * There are certain SETTINGS values that we send but cannot act upon until the
413
   * peer acknowledges them. For instance, we cannot enforce reduced stream
414
   * window sizes until the peer acknowledges the SETTINGS frame that shrinks the
415
   * size.
416
   *
417
   * There is an OutstandingSettingsFrame instance for each SETTINGS frame that
418
   * we send. We store these in a queue and associate each SETTINGS frame with
419
   * an ACK flag from the peer with a corresponding OutstandingSettingsFrame
420
   * instance.
421
   *
422
   * For details about SETTINGS synchronization via the ACK flag, see:
423
   *
424
   *   [RFC 9113] 6.5.3 Settings Synchronization
425
   */
426
  class OutstandingSettingsFrame
427
  {
428
  public:
429
0
    OutstandingSettingsFrame(const Http2ConnectionSettings &settings) : _settings(settings) {}
430
431
    /** Returns the settings parameters that were configured via the SETTINGS frame
432
     * associated with this instance.
433
     *
434
     * @return The settings parameters that were configured at the time the
435
     * associated SETTINGS frame was sent. @note that this is not just the
436
     * values in the SETTINGS frame, but those values along with all the local
437
     * settings that were in place but not explicitly configured via the frame.
438
     * Thus this returns the snapshot of the entire set of settings configured
439
     * when the SETTINGS frame was sent.
440
     */
441
    Http2ConnectionSettings const &
442
    get_outstanding_settings() const
443
0
    {
444
0
      return _settings;
445
0
    }
446
447
  private:
448
    /** The SETTINGS parameters that were set at the time of the associated
449
     * SETTINGS frame being sent.
450
     */
451
    Http2ConnectionSettings const _settings;
452
  };
453
454
  /** The queue of SETTINGS frames that we have sent but have not yet been
455
   * acknowledged by the peer. */
456
  std::queue<OutstandingSettingsFrame> _outstanding_settings_frames;
457
458
  static constexpr const int DATA_EVENT_BACKOFF_START = 10;
459
  static constexpr const int DATA_EVENT_BACKOFF_MAX   = 1000;
460
461
  // NOTE: Id of stream which MUST receive CONTINUATION frame.
462
  //   - [RFC 7540] 6.2 HEADERS
463
  //     "A HEADERS frame without the END_HEADERS flag set MUST be followed by a
464
  //     CONTINUATION frame for the same stream."
465
  //   - [RFC 7540] 6.10 CONTINUATION
466
  //     "If the END_HEADERS bit is not set, this frame MUST be followed by
467
  //     another CONTINUATION frame."
468
  Http2StreamId      continued_stream_id = 0;
469
  bool               fini_received       = false;
470
  bool               _peer_goaway_drain  = false; ///< Outbound only: an origin's GOAWAY left streams to finish before close.
471
  bool               in_destroy          = false;
472
  int                recursion           = 0;
473
  int                _data_event_backoff = DATA_EVENT_BACKOFF_START;
474
  bool               _data_event_retry   = false;
475
  Http2ShutdownState shutdown_state      = HTTP2_SHUTDOWN_NONE;
476
  Http2ErrorCode     shutdown_reason     = Http2ErrorCode::HTTP2_ERROR_MAX;
477
  Event             *shutdown_cont_event = nullptr;
478
  Event             *fini_event          = nullptr;
479
  Event             *zombie_event        = nullptr;
480
  Event             *_priority_event     = nullptr;
481
  Event             *_data_event         = nullptr;
482
  Event             *retransmit_event    = nullptr;
483
484
  int32_t configured_max_settings_frames_per_minute     = 0;
485
  int32_t configured_max_ping_frames_per_minute         = 0;
486
  int32_t configured_max_priority_frames_per_minute     = 0;
487
  int32_t configured_max_rst_stream_frames_per_minute   = 0;
488
  int32_t configured_max_continuation_frames_per_minute = 0;
489
  int32_t configured_max_empty_frames_per_minute        = 0;
490
491
  uint32_t _header_field_max_size = 32768;
492
};
493
494
///////////////////////////////////////////////
495
// INLINE
496
//
497
inline Http2StreamId
498
Http2ConnectionState::get_latest_stream_id_in() const
499
0
{
500
0
  return latest_streamid_in;
501
0
}
502
503
inline Http2StreamId
504
Http2ConnectionState::get_latest_stream_id_out() const
505
0
{
506
0
  return latest_streamid_out;
507
0
}
508
509
inline int
510
Http2ConnectionState::get_stream_requests() const
511
0
{
512
0
  return stream_requests;
513
0
}
514
515
inline void
516
Http2ConnectionState::increment_stream_requests()
517
0
{
518
0
  stream_requests++;
519
0
}
520
521
// Continuated header decoding
522
inline Http2StreamId
523
Http2ConnectionState::get_continued_stream_id() const
524
0
{
525
0
  return continued_stream_id;
526
0
}
527
528
inline void
529
Http2ConnectionState::set_continued_stream_id(Http2StreamId stream_id)
530
0
{
531
0
  continued_stream_id = stream_id;
532
0
}
533
534
inline void
535
Http2ConnectionState::clear_continued_stream_id()
536
0
{
537
0
  continued_stream_id = 0;
538
0
}
539
540
inline uint32_t
541
Http2ConnectionState::get_peer_stream_count() const
542
0
{
543
0
  return peer_streams_count_in;
544
0
}
545
546
inline void
547
Http2ConnectionState::decrement_peer_stream_count()
548
0
{
549
0
  --total_peer_streams_count;
550
0
}
551
552
inline double
553
Http2ConnectionState::get_stream_error_rate() const
554
0
{
555
0
  int total = get_stream_requests();
556
557
0
  if (static_cast<uint32_t>(total) < Http2::stream_error_sampling_threshold) {
558
0
    return 0;
559
0
  }
560
561
0
  if (total >= (1 / Http2::stream_error_rate_threshold)) {
562
0
    return (double)stream_error_count / (double)total;
563
0
  } else {
564
0
    return 0;
565
0
  }
566
0
}
567
568
inline Http2ErrorCode
569
Http2ConnectionState::get_shutdown_reason() const
570
0
{
571
0
  return shutdown_reason;
572
0
}
573
574
inline bool
575
Http2ConnectionState::is_state_closed() const
576
0
{
577
0
  return session == nullptr || fini_received;
578
0
}
579
580
inline bool
581
Http2ConnectionState::is_recursing() const
582
0
{
583
0
  return recursion > 0;
584
0
}
585
586
inline bool
587
Http2ConnectionState::is_valid_streamid(Http2StreamId id) const
588
0
{
589
0
  if (http2_is_client_streamid(id)) {
590
0
    return id <= get_latest_stream_id_in();
591
0
  } else {
592
0
    return id <= get_latest_stream_id_out();
593
0
  }
594
0
}
595
596
inline Http2ShutdownState
597
Http2ConnectionState::get_shutdown_state() const
598
0
{
599
0
  return shutdown_state;
600
0
}
601
602
inline void
603
Http2ConnectionState::set_shutdown_state(Http2ShutdownState state, Http2ErrorCode reason)
604
0
{
605
0
  shutdown_state  = state;
606
0
  shutdown_reason = reason;
607
0
}
608
609
inline Event *
610
Http2ConnectionState::get_zombie_event()
611
0
{
612
0
  return zombie_event;
613
0
}
614
615
inline void
616
Http2ConnectionState::schedule_zombie_event()
617
0
{
618
0
  if (Http2::zombie_timeout_in) { // If we have zombie debugging enabled
619
0
    if (zombie_event) {
620
0
      zombie_event->cancel();
621
0
    }
622
0
    zombie_event = this_ethread()->schedule_in(this, HRTIME_SECONDS(Http2::zombie_timeout_in));
623
0
  }
624
0
}