Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixed more parsing issues #8

Open
wants to merge 3 commits into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2011
  1. @kschzt
Commits on Nov 11, 2011
  1. fix crash when querying on closed connection

    Jaakko Manninen authored
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 9 deletions.
  1. +11 −9 lib/memcache.js
View
20 lib/memcache.js
@@ -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() {
@@ -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];
@@ -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;
Something went wrong with that request. Please try again.