return;
}
callback(response);
if (!callback.quiet || response.header.totalBodyLength === 0) {
delete(this.responseCallbacks[response.header.opaque]);
this.requestTimeouts.shift();
delete(this.errorCallbacks[response.header.opaque]);
}
};
Server.prototype.onError = function(seq, func) {
this.errorCallbacks[seq] = func;
};
Server.prototype.error = function(err) {
var errcalls = this.errorCallbacks;
this.connectCallbacks = [];
this.responseCallbacks = {};
this.requestTimeouts = [];
this.errorCallbacks = {};
this.timeoutSet = false;
if (this._socket) {
this._socket.destroy();
delete(this._socket);
}
var k;
for (k in errcalls) {
if (errcalls.hasOwnProperty(k)) {
errcalls[k](err);
}
}
};
Server.prototype.listSasl = function() {
var buf = makeRequestBuffer(0x20, '', '', '');
this.writeSASL(buf);
};
Server.prototype.saslAuth = function() {
var authStr = '\x00' + this.username + '\x00' + this.password;
var buf = makeRequestBuffer(0x21, 'PLAIN', '', authStr);
this.writeSASL(buf);
};
Server.prototype.appendToBuffer = function(dataBuf) {
var old = this.responseBuffer;
this.responseBuffer = Buffer.alloc(old.length + dataBuf.length);
old.copy(this.responseBuffer, 0);
dataBuf.copy(this.responseBuffer, old.length);
return this.responseBuffer;
};
Server.prototype.responseHandler = function(dataBuf) {
var response = parseMessage(this.appendToBuffer(dataBuf));
var respLength;
while (response) {
if (response.header.opcode === 0x20) {
this.saslAuth();
} else if (response.header.status === 0x20) {
this.error('Memcached server authentication failed!');
} else if (response.header.opcode === 0x21) {
this.emit('authenticated');
} else {
this.respond(response);
}
respLength = response.header.totalBodyLength + 24;
this.responseBuffer = this.responseBuffer.slice(respLength);
response = parseMessage(this.responseBuffer);
}
};
Server.prototype.sock = function(sasl, go) {
var self = this;
if (!self._socket) {