Skip to content

Commit

Permalink
net: Use SO_REUSEPORT for server sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Mar 24, 2024
1 parent 374334c commit c5b0955
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/net/socket/tcp_socket_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ int TCPSocketPosix::GetPeerAddress(IPEndPoint* address) const {

int TCPSocketPosix::SetDefaultOptionsForServer() {
DCHECK(socket_);

#if BUILDFLAG(IS_LINUX)
int reuseport = 1;
int rv =
setsockopt(socket_->socket_fd(), SOL_SOCKET, SO_REUSEPORT,
reinterpret_cast<const char*>(&reuseport), sizeof(reuseport));
if (rv < 0) {
return MapSystemError(errno);
}
#endif

return AllowAddressReuse();
}

Expand Down

0 comments on commit c5b0955

Please sign in to comment.