Skip to content

Commit c04cbc8

Browse files
committed
fix: improve clear_stream function with enhanced documentation and debug logging
Signed-off-by: Dengfeng Liu <[email protected]>
1 parent eff7a04 commit c04cbc8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

tcpmux.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,21 @@ void del_stream(uint32_t id) {
7777
}
7878

7979
/**
80-
* @brief Clears the hash table of all streams and sets the pointer to NULL.
80+
* @brief Clears all streams from the global hash table.
8181
*
82-
* This function checks if the global variable `all_stream` is not NULL. If it is not NULL,
83-
* it clears the hash table using `HASH_CLEAR` and then sets `all_stream` to NULL.
82+
* This function performs a complete cleanup of the global stream hash table.
83+
* It safely handles the case where the hash table is already empty.
84+
* After clearing, the global pointer is set to NULL to prevent dangling references.
85+
*
86+
* @note This function should be called during shutdown or when a complete reset is needed.
87+
* @note This is a destructive operation - all stream entries will be removed.
8488
*/
85-
void clear_stream() {
86-
if (!all_stream)
87-
return;
88-
89-
HASH_CLEAR(hh, all_stream);
90-
all_stream = NULL;
89+
void clear_stream(void) {
90+
if (all_stream) {
91+
HASH_CLEAR(hh, all_stream);
92+
all_stream = NULL;
93+
debug(LOG_DEBUG, "Cleared all streams from hash table");
94+
}
9195
}
9296

9397
/**

0 commit comments

Comments
 (0)