@@ -488,16 +488,29 @@ static uint16_t get_send_flags(struct tmux_stream *stream) {
488
488
*
489
489
* @note Window size cannot exceed MAX_STREAM_WINDOW_SIZE
490
490
*/
491
+ /**
492
+ * @brief Sends a window update message for stream flow control.
493
+ *
494
+ * Updates the receive window for a stream and sends a window update message
495
+ * if the delta exceeds half of the maximum window size or if there are flags to send.
496
+ *
497
+ * @param bout Buffered output event for sending data.
498
+ * @param stream Pointer to the tmux stream to update.
499
+ * @param length Current receive buffer length.
500
+ */
491
501
void send_window_update (struct bufferevent * bout , struct tmux_stream * stream , uint32_t length ) {
492
- uint32_t max_window = MAX_STREAM_WINDOW_SIZE ;
493
- uint32_t delta = max_window - length - stream -> recv_window ;
502
+ const uint32_t max_window = MAX_STREAM_WINDOW_SIZE ;
503
+ const uint32_t half_max_window = max_window / 2 ;
504
+ uint32_t delta = max_window > (length + stream -> recv_window )
505
+ ? max_window - length - stream -> recv_window
506
+ : 0 ;
494
507
uint16_t flags = get_send_flags (stream );
495
508
496
- if (delta < max_window / 2 && flags == 0 ) {
509
+ if (delta < half_max_window && flags == 0 ) {
497
510
return ;
498
511
}
499
512
500
- stream -> recv_window += delta ;
513
+ stream -> recv_window = MIN ( stream -> recv_window + delta , max_window ) ;
501
514
tcp_mux_send_win_update (bout , flags , stream -> id , delta );
502
515
}
503
516
0 commit comments