Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add bytesWritten and messageBytesWritten #39

Open
wants to merge 1 commit into from

2 participants

Shay Erlichmen Eric Zhang
Shay Erlichmen

No description provided.

Eric Zhang
Owner

I can't merge this because the socket doesn't always take a callback function so this wouldn't work on client side

Sorry for the late response.

In which cases socket doesn't take a callback? and also do we care, in cases where the socket doesn't take the callback you won't get the statistics info,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2013
  1. Shay Erlichmen
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 2 deletions.
  1. +11 −2 lib/stream.js
13 lib/stream.js
View
@@ -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) {
Something went wrong with that request. Please try again.