@@ -353,14 +353,40 @@ void tcp_mux_send_data(struct bufferevent *bout, uint16_t flags,
353
353
* @param bout A pointer to the bufferevent to write the ping message to.
354
354
* @param ping_id The identifier for the ping message.
355
355
*/
356
+ /**
357
+ * @brief Sends a ping message over a TCP multiplexed connection
358
+ *
359
+ * This function constructs and sends a ping message with the SYN flag set
360
+ * if TCP multiplexing is enabled. The ping message includes a unique ping ID
361
+ * for tracking responses.
362
+ *
363
+ * @param bout The bufferevent to send the ping through
364
+ * @param ping_id Unique identifier for this ping message
365
+ *
366
+ * @note Function silently returns if TCP multiplexing is disabled
367
+ * or if bufferevent is invalid
368
+ */
356
369
void tcp_mux_send_ping (struct bufferevent * bout , uint32_t ping_id ) {
357
- if (!tcp_mux_flag ())
370
+ // Early return if TCP multiplexing is disabled
371
+ if (!tcp_mux_flag ()) {
372
+ debug (LOG_DEBUG , "TCP multiplexing is disabled" );
358
373
return ;
374
+ }
359
375
376
+ // Validate bufferevent
377
+ if (!bout ) {
378
+ debug (LOG_ERR , "Invalid bufferevent for ping" );
379
+ return ;
380
+ }
381
+
382
+ // Prepare and send ping message
360
383
struct tcp_mux_header tmux_hdr ;
361
384
memset (& tmux_hdr , 0 , sizeof (tmux_hdr ));
362
385
tcp_mux_encode (PING , SYN , 0 , ping_id , & tmux_hdr );
363
- bufferevent_write (bout , (uint8_t * )& tmux_hdr , sizeof (tmux_hdr ));
386
+
387
+ if (bufferevent_write (bout , & tmux_hdr , sizeof (tmux_hdr )) < 0 ) {
388
+ debug (LOG_ERR , "Failed to send ping message" );
389
+ }
364
390
}
365
391
366
392
/**
0 commit comments