From 958776ea51745b94520fd43cb676d446b50972ee Mon Sep 17 00:00:00 2001 From: Shay Erlichmen Date: Fri, 19 Apr 2013 15:20:45 +0300 Subject: [PATCH] add bytesWritten and messageBytesWritten --- lib/stream.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/stream.js b/lib/stream.js index 7e42028..48e346d 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -20,7 +20,10 @@ function BinaryStream(socket, id, create, meta) { this._closed = false; this._ended = false; - + + this.bytesWritten = 0; + this.messageBytesWritten = 0; + if(create) { // This is a stream we are creating this._write(1, meta, this.id); @@ -73,7 +76,13 @@ BinaryStream.prototype._write = function(code, data, bonus) { return false; } var message = util.pack([code, data, bonus]); - return this._socket.send(message) !== false; + var dataLength = data ? data.length || 0 : 0; + var messageLength = message.length; + var self = this; + return this._socket.send(message, function() { + self.bytesWritten += dataLength; + self.messageBytesWritten += messageLength; + }) !== false; }; BinaryStream.prototype.write = function(data) {