Skip to content

Commit

Permalink
added set_reuseaddr to make socket reusable after an unexpected socke…
Browse files Browse the repository at this point in the history
…t close (#72)
  • Loading branch information
SushiTee authored May 5, 2024
1 parent 12ea4c6 commit ad9f89a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kissnet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,15 @@ namespace kissnet
kissnet_fatal_error("setting socket to nonblock returned an error");
}

///Set the socket option for reuse addr
/// \param state By default "false". If put to false, it will disable reuseaddr
void set_reuseaddr(bool state = false) const
{
const int reuse = state ? 1 : 0;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&reuse), sizeof(reuse)) != 0)
kissnet_fatal_error("setting socket broadcast mode returned an error");
}

///Set the socket option for broadcasts
/// \param state By default "true". If put to false, it will disable broadcasts
void set_broadcast(bool state = true) const
Expand Down

0 comments on commit ad9f89a

Please sign in to comment.