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

fixed more parsing issues #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/memcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Client.prototype.dispatchHandles = function() {
Client.prototype.query = function(query, type, callback) {
this.callbacks.push({ type: type, fun: callback });
this.sends++;
this.conn.write(query + crlf);
if (this.conn)
this.conn.write(query + crlf);
};

Client.prototype.close = function() {
Expand Down Expand Up @@ -271,14 +272,15 @@ Client.prototype.handle_get = function(buffer) {
var end_indicator_len = 3;
var result_len = 0;

if (buffer.indexOf('END') == 0) {
if (buffer.indexOf('END'+crlf) == 0) {
return [result_value, end_indicator_len + crlf_len];
} else if (buffer.indexOf('VALUE') == 0 && buffer.indexOf('END') != -1) {
first_line_len = buffer.indexOf(crlf) + crlf_len;
var end_indicator_start = buffer.indexOf('END');
result_len = end_indicator_start - first_line_len - crlf_len;
} else if (buffer.indexOf('VALUE ') == 0 && buffer.indexOf(crlf+'END'+crlf) != -1) {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var end_indicator_start = buffer.indexOf(crlf+'END'+crlf);
result_len = end_indicator_start - first_line_len;
result_value = buffer.substr(first_line_len, result_len);
return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len]
next_result_at = first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len;
return [result_value, next_result_at];
} else {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var result_len = buffer.substr(0, first_line_len).split(' ')[3];
Expand All @@ -291,12 +293,12 @@ Client.prototype.handle_get = function(buffer) {
Client.prototype.handle_stats = function(buffer){

// special case - no stats at all
if (buffer.indexOf('END') == 0){
if (buffer.indexOf('END'+crlf) == 0){
return [{}, 5];
}

// find the terminator
var idx = buffer.indexOf('\r\nEND\r\n');
var idx = buffer.indexOf(crlf+'END'+crlf);
if (idx == -1){
// wait for more data if we don't have an end yet
return null;
Expand Down