Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/xmpppy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@gmail.com>2017-05-13 10:09:09 +0300
committerJohn Smith <mrdoctorwho@gmail.com>2017-05-13 10:09:09 +0300
commit503a02c16b02d39ec1aafd9ae54370f918ae3b9a (patch)
tree7509633a9769ddf7e50ed941adbb928a5138e048
parent0c74c5e42860b5544235bd4d608dbbb93e097ad3 (diff)
Increase BUFLEN to 8192
Avanced socket configuration
-rw-r--r--xmpp/transports.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/xmpp/transports.py b/xmpp/transports.py
index 5287033..aeec11a 100644
--- a/xmpp/transports.py
+++ b/xmpp/transports.py
@@ -51,9 +51,13 @@ DATA_RECEIVED = 'DATA RECEIVED'
DATA_SENT = 'DATA SENT'
DBG_CONNECT_PROXY = 'CONNECTproxy'
-BUFLEN = 2024
+BUFLEN = 8192
SEND_INTERVAL = 0
+TCP_KEEPINTVL = 60
+TCP_KEEPIDLE = 60
+
+
class SendSemaphore(object):
def __init__(self):
@@ -81,6 +85,7 @@ class SendSemaphore(object):
def __exit__(self, *args):
self.release()
+
class error:
"""
An exception to be raised in case of low-level errors in methods of 'transports' module.
@@ -97,6 +102,23 @@ class error:
"""
return self._comment
+
+def configureSocket(sock):
+ # see man(7) tcp
+ try:
+ # enable keepalive probes
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
+ # the interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime
+ # overrides tcp_keepalive_intvl
+ sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, TCP_KEEPINTVL)
+ # the interval between the last data packet sent (simple ACKs are not considered data) and the first keepalive probe;
+ # after the connection is marked to need keepalive, this counter is not used any further
+ # overrides tcp_keepalive_time
+ sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, TCP_KEEPIDLE)
+ except (AttributeError, OSError):
+ pass
+
+
class TCPsocket(PlugIn):
"""
This class defines direct TCP connection method.
@@ -200,6 +222,7 @@ class TCPsocket(PlugIn):
except Exception:
pass
else:
+ configureSocket(self._sock)
self.DEBUG("Successfully connected to remote host %s." % repr(server), "start")
return "ok"