Permalink
Browse files

Add option for enabling TCP keepalive

  • Loading branch information...
1 parent 8f2cc9e commit db2f6fd465d2bcc99d6ff5580646f91554313159 @danielwhite danielwhite committed Dec 12, 2013
Showing with 11 additions and 2 deletions.
  1. +4 −1 include/riakc.hrl
  2. +7 −1 src/riakc_pb_socket.erl
View
@@ -1,3 +1,4 @@
+
%% -------------------------------------------------------------------
%%
%% riakc: protocol buffer client
@@ -30,7 +31,9 @@
{queue_if_disconnected, boolean()} |
{connect_timeout, pos_integer()} |
auto_reconnect |
- {auto_reconnect, boolean()}.
+ {auto_reconnect, boolean()} |
+ keepalive |
+ {keepalive, boolean()}.
%% Options for starting or modifying the connection:
%% `queue_if_disconnected' when present or true will cause requests to
%% be queued while the connection is down. `auto_reconnect' when
View
@@ -136,6 +136,7 @@
% if false, exits on connection failure/request timeout
queue_if_disconnected = false :: boolean(), % if true, add requests to queue if disconnected
sock :: port() | ssl:sslsocket(), % gen_tcp socket
+ keepalive = false :: boolean(), % if true, enabled TCP keepalive for the socket
transport = gen_tcp :: 'gen_tcp' | 'ssl',
active :: #request{} | undefined, % active request
queue :: queue() | undefined, % queue of pending requests
@@ -1386,6 +1387,10 @@ parse_options([{auto_reconnect,Bool}|Options], State) when
parse_options(Options, State#state{auto_reconnect = Bool});
parse_options([auto_reconnect|Options], State) ->
parse_options([{auto_reconnect, true}|Options], State);
+parse_options([{keepalive,Bool}|Options], State) when is_boolean(Bool) ->
+ parse_options(Options, State#state{keepalive = Bool});
+parse_options([keepalive|Options], State) ->
+ parse_options([{keepalive, false}|Options], State);
parse_options([{credentials, User, Pass}|Options], State) ->
parse_options(Options, State#state{credentials={User, Pass}});
parse_options([{certfile, File}|Options], State) ->
@@ -1943,7 +1948,8 @@ restart_req_timer(Request) ->
connect(State) when State#state.sock =:= undefined ->
#state{address = Address, port = Port, connects = Connects} = State,
case gen_tcp:connect(Address, Port,
- [binary, {active, once}, {packet, 4}],
+ [binary, {active, once}, {packet, 4},
+ {keepalive, State#state.keepalive}],
State#state.connect_timeout) of
{ok, Sock} ->
State1 = State#state{sock = Sock, connects = Connects+1,

0 comments on commit db2f6fd

Please sign in to comment.