Skip to content

Commit

Permalink
Use SO_REUSEPORT on Transport::UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
mmasaki committed Dec 15, 2023
1 parent bc55f22 commit a2c8135
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions worker/src/RTC/PortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ namespace RTC
{
case Transport::UDP:
{
#ifdef defined(__linux__) && defined(SO_REUSEPORT)
uv_os_fd_t fd;
uint32_t yes = 1;

if (uv_fileno(uvHandle, &fd) == 0) {
flags |= UV_UDP_REUSEADDR;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
}
#endif

err = uv_udp_bind(
reinterpret_cast<uv_udp_t*>(uvHandle),
reinterpret_cast<const struct sockaddr*>(&bindAddr),
Expand Down Expand Up @@ -472,6 +482,16 @@ namespace RTC
{
case Transport::UDP:
{
#ifdef defined(__linux__) && defined(SO_REUSEPORT)
uv_os_fd_t fd;
uint32_t yes = 1;

if (uv_fileno(uvHandle, &fd) == 0) {
flags |= UV_UDP_REUSEADDR;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
}
#endif

err = uv_udp_bind(
reinterpret_cast<uv_udp_t*>(uvHandle),
reinterpret_cast<const struct sockaddr*>(&bindAddr),
Expand Down

0 comments on commit a2c8135

Please sign in to comment.