Clarify setting socket_options
There was a lot of code that would have no effect if kwargs already had socket_options set. To make the code clearer, only execute the code if it's going to have an effect. Change-Id: Ic42f5a0bac07113aff59d36d19293dc6d65cd58a
This commit is contained in:
@@ -906,28 +906,30 @@ class TCPKeepAliveAdapter(requests.adapters.HTTPAdapter):
|
|||||||
http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx
|
http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx
|
||||||
"""
|
"""
|
||||||
def init_poolmanager(self, *args, **kwargs):
|
def init_poolmanager(self, *args, **kwargs):
|
||||||
socket_options = [
|
if 'socket_options' not in kwargs:
|
||||||
# Keep Nagle's algorithm off
|
socket_options = [
|
||||||
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
|
# Keep Nagle's algorithm off
|
||||||
# Turn on TCP Keep-Alive
|
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
|
||||||
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
|
# Turn on TCP Keep-Alive
|
||||||
# Set the maximum number of keep-alive probes
|
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
|
||||||
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4),
|
# Set the maximum number of keep-alive probes
|
||||||
# Send keep-alive probes every 15 seconds
|
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4),
|
||||||
(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 15),
|
# Send keep-alive probes every 15 seconds
|
||||||
]
|
(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 15),
|
||||||
|
|
||||||
# Some operating systems (e.g., OSX) do not support setting
|
|
||||||
# keepidle
|
|
||||||
if hasattr(socket, 'TCP_KEEPIDLE'):
|
|
||||||
socket_options += [
|
|
||||||
# Wait 60 seconds before sending keep-alive probes
|
|
||||||
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# After waiting 60 seconds, and then sending a probe once every 15
|
# Some operating systems (e.g., OSX) do not support setting
|
||||||
# seconds 4 times, these options should ensure that a connection
|
# keepidle
|
||||||
# hands for no longer than 2 minutes before a ConnectionError is
|
if hasattr(socket, 'TCP_KEEPIDLE'):
|
||||||
# raised.
|
socket_options += [
|
||||||
kwargs.setdefault('socket_options', socket_options)
|
# Wait 60 seconds before sending keep-alive probes
|
||||||
|
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
|
||||||
|
]
|
||||||
|
|
||||||
|
# After waiting 60 seconds, and then sending a probe once every 15
|
||||||
|
# seconds 4 times, these options should ensure that a connection
|
||||||
|
# hands for no longer than 2 minutes before a ConnectionError is
|
||||||
|
# raised.
|
||||||
|
|
||||||
|
kwargs['socket_options'] = socket_options
|
||||||
super(TCPKeepAliveAdapter, self).init_poolmanager(*args, **kwargs)
|
super(TCPKeepAliveAdapter, self).init_poolmanager(*args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user