Skip to content

Commit

Permalink
feat(udp): add explicit unsubscribe function to facilitate clean shut…
Browse files Browse the repository at this point in the history
…down

Signed-off-by: Max SCHMELLER <[email protected]>
  • Loading branch information
mojomex committed Nov 21, 2024
1 parent 65ef33d commit 84e5493
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,20 @@ class UdpSocket
return *this;
}

~UdpSocket()
/**
* @brief Gracefully stops the active receiver thread (if any) but keeps the socket alive. The
* same socket can later be subscribed again.
*/
UdpSocket & unsubscribe()
{
if (state_ == State::ACTIVE) state_ = State::BOUND;
if (receive_thread_.joinable()) receive_thread_.join();
return *this;
}

~UdpSocket()
{
unsubscribe();
close(sock_fd_);
}

Expand Down

0 comments on commit 84e5493

Please sign in to comment.