Skip to content

Commit

Permalink
fix: improve clear_stream function with enhanced documentation and de…
Browse files Browse the repository at this point in the history
…bug logging

Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
  • Loading branch information
liudf0716 committed Nov 13, 2024
1 parent eff7a04 commit c04cbc8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tcpmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ void del_stream(uint32_t id) {
}

/**
* @brief Clears the hash table of all streams and sets the pointer to NULL.
* @brief Clears all streams from the global hash table.
*
* This function checks if the global variable `all_stream` is not NULL. If it is not NULL,
* it clears the hash table using `HASH_CLEAR` and then sets `all_stream` to NULL.
* This function performs a complete cleanup of the global stream hash table.
* It safely handles the case where the hash table is already empty.
* After clearing, the global pointer is set to NULL to prevent dangling references.
*
* @note This function should be called during shutdown or when a complete reset is needed.
* @note This is a destructive operation - all stream entries will be removed.
*/
void clear_stream() {
if (!all_stream)
return;

HASH_CLEAR(hh, all_stream);
all_stream = NULL;
void clear_stream(void) {
if (all_stream) {
HASH_CLEAR(hh, all_stream);
all_stream = NULL;
debug(LOG_DEBUG, "Cleared all streams from hash table");
}
}

/**
Expand Down

0 comments on commit c04cbc8

Please sign in to comment.