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 {