From b248e96dc2582f0176b3a75468fa18ab0036c3e1 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 14 Oct 2015 01:38:17 +0900 Subject: [PATCH] Output a warning instead of crashing if ZMQ library is too old to support TCP keepalive options. Fixes #109. --- lib/util/zmqutil.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/util/zmqutil.js b/lib/util/zmqutil.js index ef316fcb..8c5fc39c 100644 --- a/lib/util/zmqutil.js +++ b/lib/util/zmqutil.js @@ -6,9 +6,18 @@ var zmq = require('zmq') +var log = require('./logger').createLogger('util:zmqutil') + module.exports.socket = function() { var sock = zmq.socket.apply(zmq, arguments) - sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE, 1) - sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE_IDLE, 300000) + + try { + sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE, 1) + sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE_IDLE, 300000) + } + catch (err) { + log.warn('ZeroMQ library too old, no support for TCP keepalive options') + } + return sock }