Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

64kb scratch (gotta grow this)

  • Loading branch information...
commit d4ad1f58aea09d6e434a9bf1c3f38a9ad1cc0a0d 1 parent 1a1057a
@tj authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/connection.js
View
15 lib/connection.js
@@ -33,8 +33,10 @@ var stub = {
var Connection = module.exports = function Connection(server, stream) {
this.server = server;
this.state = 'request';
- this.tmp = new Buffer(256);
+ this.tmp = new Buffer(128);
this.tmp.pos = 0;
+ this.buf = new Buffer(64 * 1024); // TODO: grow
+ this.buf.pos = 0;
this.stream = stream || stub;
this.stream.on('data', this.parse.bind(this));
};
@@ -108,6 +110,7 @@ Connection.prototype.error = function(msg){
this.stream.write('-ERR ' + msg + '\r\n');
this.state = 'request';
this.tmp.pos = 0;
+ this.buf.pos = 0;
this.multiple = null;
this.cmd = null;
return true;
@@ -201,9 +204,9 @@ Connection.prototype.invoke = function(cmd, args){
Connection.prototype.bufferArgument = function(){
// Push argument Buffer
- var len = this.tmp.pos
+ var len = this.buf.pos
, arg = new Buffer(len);
- this.tmp.copy(arg, 0, 0, len);
+ this.buf.copy(arg, 0, 0, len);
arg.pos = len;
this.args.push(arg);
};
@@ -214,7 +217,7 @@ Connection.prototype.bufferArgument = function(){
Connection.prototype.bufferCommand = function(){
var fn;
- this.cmd = string(this.tmp).toLowerCase();
+ this.cmd = string(this.buf).toLowerCase();
// Command is valid
if (fn = commands[this.cmd]) {
var multiple = this.multiple = fn.multiple
@@ -376,7 +379,7 @@ Connection.prototype.parse = function(buf){
return this.error('missing carriage return for bulk data');
}
} else {
- this.tmp[this.tmp.pos++] = buf[pos++];
+ this.buf[this.buf.pos++] = buf[pos++];
}
break;
@@ -392,7 +395,7 @@ Connection.prototype.parse = function(buf){
this.invoke(this.cmd, this.args);
}
this.state = 'request';
- this.tmp.pos = 0;
+ this.buf.pos = 0;
// Error
} else {
return this.error('missing line feed for bulk data');
Please sign in to comment.
Something went wrong with that request. Please try again.