Skip to content

Commit 0fbb95b

Browse files
authored
Merge pull request excon#665 from outstand/add-keepalive
Add support for tcp keepalive
2 parents 97d2336 + ef37e55 commit 0fbb95b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/excon/constants.rb

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ module Excon
7979
:private_key_path,
8080
:connect_timeout,
8181
:family,
82+
:keepalive,
8283
:host,
8384
:hostname,
8485
:omit_default_port,

lib/excon/socket.rb

+9
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ def connect
168168
::Socket::TCP_NODELAY,
169169
true)
170170
end
171+
172+
if @data[:keepalive]
173+
if [:SOL_SOCKET, :SO_KEEPALIVE, :SOL_TCP, :TCP_KEEPIDLE, :TCP_KEEPINTVL, :TCP_KEEPCNT].all?{|c| ::Socket.const_defined? c}
174+
@socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true)
175+
@socket.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPIDLE, @data[:keepalive][:time])
176+
@socket.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPINTVL, @data[:keepalive][:intvl])
177+
@socket.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPCNT, @data[:keepalive][:probes])
178+
end
179+
end
171180
end
172181

173182
def read_nonblock(max_length)

0 commit comments

Comments
 (0)