Permalink
Browse files

Merge pull request #39 from ffissore/master

initial buffer may be longer than expected
  • Loading branch information...
2 parents d51ae10 + 8fe2eef commit 6ed27b4c76ef945256592ccfc7bda74a3198a6a6 @ffissore ffissore committed May 17, 2012
Showing with 11 additions and 5 deletions.
  1. +1 −1 lib/orientdb/commands/CommandBase.js
  2. +10 −4 lib/orientdb/connection/manager.js
@@ -38,7 +38,7 @@ command.prototype.read = function(buf) {
}
// Tell the caller how much of the buffer was consumed.
- return totalBytesRead > buf.length ? buf.length : totalBytesRead;
+ return totalBytesRead;
};
command.skipByte = function(buf, offset) {
@@ -135,14 +135,16 @@ Manager.prototype.addSocketListeners = function(socket, callback) {
return;
}
first = false;
-
- } else {
- self.readResponse(data);
+ var remainingData = new Buffer(data.length - parser.BYTES_SHORT);
+ data.copy(remainingData, 0, parser.BYTES_SHORT);
+ data = remainingData;
}
+
+ self.readResponse(data);
});
socket.on("close", function(hadError) {
- debug.log("Closed " + hadError);
+ debug.log("Closed (error: " + hadError + ")");
});
};
@@ -155,6 +157,10 @@ Manager.prototype.addSocketListeners = function(socket, callback) {
Parse data received from socket.
------------------------------------------------------------------------------*/
Manager.prototype.readResponse = function(data) {
+ if (data.length === 0) {
+ return;
+ }
+
var self = this,
bytesRead = 0,
bytesConsumed = 0,

0 comments on commit 6ed27b4

Please sign in to comment.