reconnect cleanup

This commit is contained in:
Mark Cavage 2011-11-09 14:55:13 -08:00
parent 8fdff3e06d
commit df159475c8
2 changed files with 10 additions and 7 deletions

View File

@ -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'));

View File

@ -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();
});