Unverified Commit 8ff47980 authored by Da Zheng's avatar Da Zheng Committed by GitHub
Browse files

[RPC] Make the port reusable after the socket is closed. (#2418)



* reuse.

* fix compile.
Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-2-202.us-west-1.compute.internal>
parent 9d7bf4ea
...@@ -30,6 +30,13 @@ TCPSocket::TCPSocket() { ...@@ -30,6 +30,13 @@ TCPSocket::TCPSocket() {
if (socket_ < 0) { if (socket_ < 0) {
LOG(FATAL) << "Can't create new socket. Errno=" << errno; LOG(FATAL) << "Can't create new socket. Errno=" << errno;
} }
#ifndef _WIN32
// This is to make sure the same port can be reused right after the socket is closed.
int enable = 1;
if (setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
LOG(WARNING) << "cannot make the socket reusable. Errno=" << errno;
}
#endif // _WIN32
} }
TCPSocket::~TCPSocket() { TCPSocket::~TCPSocket() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment