Blob Blame History Raw
From 2c1ee2d8803dfd37c7fb72d313aaaa2f71e83bf6 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Wed, 5 Dec 2012 10:47:14 -0500
Subject: [PATCH] Allow the user to set TCP keepalive options.

---
 txzmq/connection.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/txzmq/connection.py b/txzmq/connection.py
index 0458758..11166d8 100644
--- a/txzmq/connection.py
+++ b/txzmq/connection.py
@@ -63,6 +63,12 @@ class ZmqConnection(object):
     multicastRate = 100
     highWaterMark = 0
 
+    # Only supported by zeromq3 and pyzmq>=2.2.0.1
+    tcpKeepalive = 0
+    tcpKeepaliveCount = 0
+    tcpKeepaliveIdle = 0
+    tcpKeepaliveInterval = 0
+
     def __init__(self, factory, endpoint=None, identity=None):
         """
         Constructor.
@@ -100,6 +106,16 @@ class ZmqConnection(object):
             self.socket.setsockopt(constants.SNDHWM, self.highWaterMark)
             self.socket.setsockopt(constants.RCVHWM, self.highWaterMark)
 
+        if ZMQ3 and self.tcpKeepalive:
+            self.socket.setsockopt(
+                constants.TCP_KEEPALIVE, self.tcpKeepalive)
+            self.socket.setsockopt(
+                constants.TCP_KEEPALIVE_CNT, self.tcpKeepaliveCount)
+            self.socket.setsockopt(
+                constants.TCP_KEEPALIVE_IDLE, self.tcpKeepaliveIdle)
+            self.socket.setsockopt(
+                constants.TCP_KEEPALIVE_INTVL, self.tcpKeepaliveInterval)
+
         if self.identity is not None:
             self.socket.setsockopt(constants.IDENTITY, self.identity)
 
-- 
1.8.0.1