Skip to content

Commit

Permalink
Set SO_REUSEADDR on the server socket, to allow the agent to bind to …
Browse files Browse the repository at this point in the history
…the listening port after being restarted.
  • Loading branch information
sp193 committed Aug 25, 2019
1 parent 4aaeef5 commit 86f42f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cpp/transport/tcp/TCPServerLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ bool TCPv4Agent::init()

if (-1 != listener_poll_.fd)
{
/* Set reuse port. */
int reuse = 1;
if (-1 == setsockopt(listener_poll_.fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)))
{
UXR_AGENT_LOG_ERROR(
UXR_DECORATE_RED("socket opt error"),
"Port: {}",
listener_poll_.fd);
return false;
}

/* IP and Port setup. */
struct sockaddr_in address;
address.sin_family = AF_INET;
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/transport/tcp/TCPServerWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ bool TCPv4Agent::init()

if (INVALID_SOCKET != listener_poll_.fd)
{
/* Set reuse port. */
int reuse = 1;
if (-1 == setsockopt(listener_poll_.fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuse, sizeof(reuse)))
{
UXR_AGENT_LOG_ERROR(
UXR_DECORATE_RED("socket opt error"),
"Port: {}",
listener_poll_.fd);
return false;
}

/* IP and Port setup. */
struct sockaddr_in address;
address.sin_family = AF_INET;
Expand Down

0 comments on commit 86f42f1

Please sign in to comment.