@@ -137,6 +137,8 @@ pub struct StreamsState {
137137
138138 /// The shrink to be applied to local_max_data when receive_window is shrunk
139139 receive_window_shrink_debt : u64 ,
140+ /// Whether the locally-initiated stream limit has been hit, per direction
141+ pub ( super ) streams_blocked : [ bool ; 2 ] ,
140142}
141143
142144impl StreamsState {
@@ -181,6 +183,7 @@ impl StreamsState {
181183 initial_max_stream_data_bidi_local : 0u32 . into ( ) ,
182184 initial_max_stream_data_bidi_remote : 0u32 . into ( ) ,
183185 receive_window_shrink_debt : 0 ,
186+ streams_blocked : [ false , false ] ,
184187 } ;
185188
186189 for dir in Dir :: iter ( ) {
@@ -525,6 +528,32 @@ impl StreamsState {
525528 Dir :: Bi => stats. max_streams_bidi += 1 ,
526529 }
527530 }
531+
532+ // STREAMS_BLOCKED
533+ for dir in Dir :: iter ( ) {
534+ if self . streams_blocked [ dir as usize ] {
535+ pending. streams_blocked [ dir as usize ] = true ;
536+ self . streams_blocked [ dir as usize ] = false ;
537+ }
538+
539+ if !pending. streams_blocked [ dir as usize ] || buf. len ( ) + 9 >= max_size {
540+ continue ;
541+ }
542+
543+ pending. streams_blocked [ dir as usize ] = false ;
544+ retransmits. get_or_create ( ) . streams_blocked [ dir as usize ] = true ;
545+ let limit = self . max [ dir as usize ] ;
546+ trace ! ( limit, "STREAMS_BLOCKED ({:?})" , dir) ;
547+ buf. write ( match dir {
548+ Dir :: Uni => frame:: FrameType :: STREAMS_BLOCKED_UNI ,
549+ Dir :: Bi => frame:: FrameType :: STREAMS_BLOCKED_BIDI ,
550+ } ) ;
551+ buf. write_var ( limit) ;
552+ match dir {
553+ Dir :: Uni => stats. streams_blocked_uni += 1 ,
554+ Dir :: Bi => stats. streams_blocked_bidi += 1 ,
555+ }
556+ }
528557 }
529558
530559 pub ( crate ) fn write_stream_frames (
@@ -697,6 +726,7 @@ impl StreamsState {
697726 let current = & mut self . max [ dir as usize ] ;
698727 if count > * current {
699728 * current = count;
729+ self . streams_blocked [ dir as usize ] = false ;
700730 self . events . push_back ( StreamEvent :: Available { dir } ) ;
701731 }
702732
0 commit comments