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) {