From abdd4890e59b54c12e9f01af7dbe12b6344840b7 Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Fri, 18 Jul 2014 10:29:46 -0500 Subject: [PATCH] Move client.connect into public API In cases where a reconnect-enabled client has been manually disconnected via unbind, it may be desirable to initiate a reconnect without incurring other client actions. --- lib/client/client.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index 4d4b15a..65015b6 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -343,7 +343,7 @@ function Client(options) { this.socket = null; this.connected = false; - this._connect(); + this.connect(); } util.inherits(Client, EventEmitter); module.exports = Client; @@ -861,13 +861,11 @@ Client.prototype.destroy = function destroy(err) { }; -///--- Private API - /** * Initiate LDAP connection. */ -Client.prototype._connect = function _connect() { - if (this.connecting) { +Client.prototype.connect = function connect() { + if (this.connecting || this.connected) { return; } var self = this; @@ -1103,6 +1101,10 @@ Client.prototype._connect = function _connect() { retry.backoff(); }; + + +///--- Private API + /** * Flush queued requests out to the socket. */ @@ -1153,7 +1155,7 @@ Client.prototype._onClose = function _onClose(had_err) { // Automatically fire reconnect logic if the socket was closed for any reason // other than a user-initiated unbind. if (this.reconnect && !this.unbound) { - this._connect(); + this.connect(); } this.unbound = false; return false; @@ -1218,7 +1220,7 @@ Client.prototype._send = function _send(message, } // Initiate reconnect if needed if (this.reconnect) { - this._connect(); + this.connect(); } return false; } else {