-
-
Save havenwood/bdf4aaec6824840caf53226264636333 to your computer and use it in GitHub Desktop.
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
require 'rmodbus' | |
module ModBus | |
class Client | |
def set_keepalive keepalive: true, keepidle: 50, keepintvl: 10, keepcnt: 5 | |
@io.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, keepalive | |
@io.setsockopt Socket::SOL_TCP, Socket::TCP_KEEPIDLE, keepidle | |
@io.setsockopt Socket::SOL_TCP, Socket::TCP_KEEPINTVL, keepintvl | |
@io.setsockopt Socket::SOL_TCP, Socket::TCP_KEEPCNT, keepcnt | |
rescue | |
warn 'TCP keepalive parameters not set. Continuing.' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment