From c9f241700f3746768df11a51fb55d753ec01b309 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 3 Jun 2014 00:41:44 +0200 Subject: [PATCH] Allow existing Socket object to be injected. --- lib/Connection.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 6bacc05..b9080eb 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -47,6 +47,7 @@ function Connection(config) { config || (config = {}); this._config = { + socket: config.socket, host: config.host || 'localhost', port: config.port || 143, tls: config.tls, @@ -63,7 +64,7 @@ function Connection(config) { : true) }; - this._sock = undefined; + this._sock = config.socket || undefined; this._tagcount = 0; this._tmrConn = undefined; this._tmrKeepalive = undefined; @@ -83,7 +84,7 @@ inherits(Connection, EventEmitter); Connection.prototype.connect = function() { var config = this._config, self = this, socket, parser, tlsOptions; - socket = new Socket(); + socket = config.socket || new Socket(); socket.setKeepAlive(true); socket.setTimeout(0); this._sock = undefined;