Permalink
Browse files

Merge pull request #41 from ffissore/master

closes #40
  • Loading branch information...
2 parents 6ed27b4 + 0580e39 commit 598e923f4033fefe07b11617c1b2d1285a3a4102 @ffissore ffissore committed May 18, 2012
Showing with 5 additions and 20 deletions.
  1. +2 −6 lib/orientdb/commands/CommandBase.js
  2. +3 −14 lib/orientdb/connection/manager.js
@@ -33,12 +33,8 @@ command.prototype.read = function(buf) {
localBuffer.copy(this.lingeringBuffer, 0, totalBytesRead);
- if (!this.done()) {
- totalBytesRead = buf.length;
- }
-
- // Tell the caller how much of the buffer was consumed.
- return totalBytesRead;
+ // Give back the remaining buffer to the caller
+ return this.lingeringBuffer;
};
command.skipByte = function(buf, offset) {
@@ -162,18 +162,9 @@ Manager.prototype.readResponse = function(data) {
}
var self = this,
- bytesRead = 0,
- bytesConsumed = 0,
- bytesAvailable = data.length,
- command = self.currentCommand,
- buffer = new Buffer(bytesAvailable);
+ command = self.currentCommand;
do {
- // Each time through the loop, the unread portion of the buffer
- // is copied into buffer. This allows zero-based
- // indexing on every iteration, even if the raw buffer from the
- // socket contains more than one response.
- data.copy(buffer, 0, bytesConsumed);
if (!command || command.instance.done()) {
command = self.currentCommand = commandQueue.shift();
@@ -197,7 +188,7 @@ Manager.prototype.readResponse = function(data) {
debug.log("Response - Operation " + command.operationType + " (sid: " + command.sequence + ", size: " + data.length + ")");
- bytesRead = command.instance.read(buffer, function(err, result) {
+ data = command.instance.read(data, function(err, result) {
if (err) {
if (command.callback) {
command.callback(err);
@@ -210,8 +201,6 @@ Manager.prototype.readResponse = function(data) {
}
});
- bytesConsumed += bytesRead;
-
// For commands that maintain a state, if the state became "done"
// or "error" on this loop iteration, fire the callback.
if (command.instance.error) {
@@ -220,7 +209,7 @@ Manager.prototype.readResponse = function(data) {
command.callback(null, command.instance.result);
}
- } while (bytesConsumed < bytesAvailable);
+ } while (data.length > 0 && command.instance.done());
};
/*------------------------------------------------------------------------------

0 comments on commit 598e923

Please sign in to comment.