79327824

Date: 2025-01-03 22:27:45
Score: 1
Natty:
Report link

Yes, you can subclass Net::HTTP, override the private on_connect method, then use setsockopt on @socket.io.setsockopt to set the socket options including TCP Keepalive, e.g.

class KeepaliveHttp < Net::HTTP
  def on_connect
    @socket.io.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
    @socket.io.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPIDLE, 5)
    @socket.io.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPINTVL, 20)
    @socket.io.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPCNT, 5)
  end
end

Inspired by this answer: https://stackoverflow.com/a/73704394/994496

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Emil O