From df159475c83adf4a4544e98ba0a442ba1a7f6aa6 Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Wed, 9 Nov 2011 14:55:13 -0800 Subject: [PATCH] reconnect cleanup --- lib/client.js | 8 +++++++- tst/client.test.js | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/client.js b/lib/client.js index 13b2f4d..9691da4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -212,6 +212,7 @@ Client.prototype.bind = function(name, credentials, controls, callback, conn) { if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); + this.connect(); var self = this; var req = new BindRequest({ @@ -677,6 +678,9 @@ Client.prototype.unbind = function(callback) { this._bindDN = null; this._credentials = null; + if (!this.connect) + return callback(); + var req = new UnbindRequest(); return self._send(req, 'unbind', callback); }; @@ -693,7 +697,9 @@ Client.prototype._send = function(message, expect, callback, connection) { var self = this; function closedConn() { - conn.destroy(); + if (conn) + conn.destroy(); + if (typeof(callback) === 'function') return callback(new ConnectionError('no connection')); diff --git a/tst/client.test.js b/tst/client.test.js index 164f9c9..f0a4ca2 100644 --- a/tst/client.test.js +++ b/tst/client.test.js @@ -566,19 +566,16 @@ test('abandon (GH-27)', function(t) { }); -test('unbind and reconnect (GH-30)', function(t) { +test('unbind (GH-30)', function(t) { client.unbind(function(err) { t.ifError(err); - client.once('connect', function() { - t.end(); - }); - client.connect(); + t.end(); }); }); + test('shutdown', function(t) { client.unbind(function(err) { - t.ifError(err); server.on('close', function() { t.end(); });