File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from six import PY2
44from threading import Thread
55from riak .riak_object import RiakObject
6+ from riak .transports .tcp import TcpTransport
67from riak .tests import DUMMY_HTTP_PORT , DUMMY_PB_PORT , RUN_POOL
78from riak .tests .base import IntegrationTestBase
89
1314
1415
1516class ClientTests (IntegrationTestBase , unittest .TestCase ):
17+ def test_can_set_tcp_keepalive (self ):
18+ if self .protocol == 'pbc' :
19+ topts = {'socket_keepalive' : True }
20+ c = self .create_client (transport_options = topts )
21+ for i , r in enumerate (c ._tcp_pool .resources ):
22+ self .assertIsInstance (r , TcpTransport )
23+ self .assertTrue (r ._socket_keepalive )
24+ c .close ()
25+ else :
26+ pass
27+
1628 def test_uses_client_id_if_given (self ):
1729 if self .protocol == 'pbc' :
1830 zero_client_id = "\0 \0 \0 \0 "
Original file line number Diff line number Diff line change @@ -195,12 +195,13 @@ def _connect(self):
195195 self ._timeout )
196196 else :
197197 self ._socket = socket .create_connection (self ._address )
198+ if self ._socket_tcp_options :
199+ ka_opts = self ._socket_tcp_options
200+ for k , v in ka_opts .iteritems ():
201+ self ._socket .setsockopt (socket .SOL_TCP , k , v )
198202 if self ._socket_keepalive :
199203 self ._socket .setsockopt (
200204 socket .SOL_SOCKET , socket .SO_KEEPALIVE , 1 )
201- ka_opts = self ._socket_keepalive_options or {}
202- for k , v in ka_opts .iteritems ():
203- self ._socket .setsockopt (socket .SOL_TCP , k , v )
204205 if self ._client ._credentials :
205206 self ._init_security ()
206207
Original file line number Diff line number Diff line change @@ -25,8 +25,6 @@ def __init__(self,
2525 node = None ,
2626 client = None ,
2727 timeout = None ,
28- socket_keepalive = False ,
29- socket_keepalive_options = None ,
3028 ** kwargs ):
3129 super (TcpTransport , self ).__init__ ()
3230
@@ -35,11 +33,14 @@ def __init__(self,
3533 self ._address = (node .host , node .pb_port )
3634 self ._timeout = timeout
3735 self ._socket = None
38- self ._socket_keepalive = socket_keepalive
39- self ._socket_keepalive_options = socket_keepalive_options
4036 self ._pbuf_c = None
4137 self ._ttb_c = None
42- self ._use_ttb = kwargs .get ('use_ttb' , True )
38+ self ._socket_tcp_options = \
39+ kwargs .get ('socket_tcp_options' , {})
40+ self ._socket_keepalive = \
41+ kwargs .get ('socket_keepalive' , False )
42+ self ._use_ttb = \
43+ kwargs .get ('use_ttb' , True )
4344
4445 def _get_pbuf_codec (self ):
4546 if not self ._pbuf_c :
You can’t perform that action at this time.
0 commit comments