Skip to content

Commit

Permalink
Set socket reuse flag in socket creation (#161)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #161

set the socket reuse flag for the communication agent to avoid timeouts

Reviewed By: RuiyuZhu

Differential Revision: D35207812

fbshipit-source-id: 4bb516db98f963e29165a873f889a5f24fde0840
  • Loading branch information
adshastri authored and facebook-github-bot committed Mar 29, 2022
1 parent 7baf466 commit 6412483
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fbpcf/engine/communication/SocketPartyCommunicationAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ int SocketPartyCommunicationAgent::connectToHost(
throw std::runtime_error("error opening socket");
}

int enable = 1;

if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
XLOG(INFO) << "setsockopt(SO_REUSEADDR) failed";
}

while (connect(sockfd, addrs->ai_addr, addrs->ai_addrlen) < 0) {
// wait a second and retry
usleep(1000);
Expand All @@ -147,6 +153,11 @@ int SocketPartyCommunicationAgent::receiveFromClient(int portNo) {
if (sockfd < 0) {
throw std::runtime_error("error opening socket");
}
int enable = 1;

if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
XLOG(INFO) << "setsockopt(SO_REUSEADDR) failed";
}

struct sockaddr_in servAddr;

Expand Down

0 comments on commit 6412483

Please sign in to comment.