-
-
Save zerowidth/3144130 to your computer and use it in GitHub Desktop.
child socket port re-binding test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# only way to get the child process to re-bind is to set SO_REUSEPORT on both | |
# the parent socket and the child socket before binding. | |
require "socket" | |
puts "in parent" | |
server = TCPServer.new("127.0.0.1", 4000) | |
server.setsockopt(:SOCKET, :REUSEPORT, true) | |
puts server.inspect | |
if fork | |
Process.wait | |
else | |
puts "in child" | |
child_server = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) | |
child_server.setsockopt(:SOCKET, :REUSEPORT, true) | |
child_server.bind(Socket.pack_sockaddr_in(4000, '127.0.0.1')) | |
puts child_server.inspect | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah that's the option i was thinking of. so to be very durable the parent would need to un-bind to allow bad children to work...