Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcal committed Aug 28, 2010
1 parent 7bb0c83 commit 973c883
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions lib/memcache.js
Expand Up @@ -168,44 +168,46 @@ Client.prototype.decrement = function(key, value, callback) {
return this.query('decr ' + key + ' ' + value, 'simple', callback);
};

Client.prototype.handle_received_data = function () {
var self = this;
Client.prototype.handle_received_data = function(){

while (this.buffer.length > 0) {
var result = this.determine_reply_handler(this.buffer);

if (result == null) {
break;
}

var result_value = result[0];
var next_result_at = result[1];
var result_error = result[2];

if (next_result_at > this.buffer.length) {
break;
}

var callback = this.callbacks.shift();

this.buffer = this.buffer.substring(next_result_at);
if (callback != null && callback.fun) {
this.replies += 1;
callback.fun(result_value, result_error);
}
}
while (this.buffer.length > 0) {

var result = this.determine_reply_handler(this.buffer);

if (result == null) {
break;
}

var result_value = result[0];
var next_result_at = result[1];
var result_error = result[2];

// does the current message need more data than we have?
// (this is how "get" ops ensure we've gotten all the data)
if (next_result_at > this.buffer.length){
break;
}

this.buffer = this.buffer.substring(next_result_at);

var callback = this.callbacks.shift();
if (callback != null && callback.fun){
this.replies++;
callback.fun(result_value, result_error);
}
}
};

Client.prototype.determine_reply_handler = function (buffer) {
Client.prototype.determine_reply_handler = function (buffer){

// check we have a whole line in the buffer
var crlf_at = buffer.indexOf(crlf);
if (crlf_at == -1) {
if (crlf_at == -1){
return null;
}

// determine errors
for (var error_idx in error_replies) {
for (var error_idx in error_replies){
var error_indicator = error_replies[error_idx];
if (buffer.indexOf(error_indicator) == 0) {
return this.handle_error(buffer);
Expand Down Expand Up @@ -250,7 +252,7 @@ Client.prototype.handle_version = function(buffer){
};

Client.prototype.handle_error = function(buffer){
line = readLine(buffer);
line = readLine(buffer);
return [null, (line.length + crlf_len), line];
};

Expand Down

0 comments on commit 973c883

Please sign in to comment.