TCPServer use SO_REUSEADDR if possible

This commit is contained in:
rhykw
2016-05-28 09:33:53 +09:00
parent 2a80cccf30
commit 4f6703203b
+3 -1
View File
@@ -262,7 +262,9 @@ class TCPServer
ai = Addrinfo.getaddrinfo(host, service, nil, nil, nil, Socket::AI_PASSIVE)[0]
@init_with_fd = true
super(Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0), "r+")
self.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
if Socket.const_defined?(:SO_REUSEADDR)
self.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
end
Socket._bind(self.fileno, ai.to_sockaddr)
listen(5)
self