diff options
author | Alexander Uvarov <alexander.uvarov@gmail.com> | 2011-07-21 12:20:01 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-07-25 15:28:38 +0400 |
commit | 14b75a126f27286fea12bf1f918b8beb7abf01dd (patch) | |
tree | 00ef60cd77fed9b2074aa1c3ac3fdc736b7425e6 /lib | |
parent | c050d0fa19a2dbb34e1e99403b597a5e8e51b6e5 (diff) |
Add Socket::bytesRead, Socket::bytesWritten
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net_legacy.js | 6 | ||||
-rw-r--r-- | lib/net_uv.js | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/net_legacy.js b/lib/net_legacy.js index b2b997718b1..1a383325136 100644 --- a/lib/net_legacy.js +++ b/lib/net_legacy.js @@ -207,6 +207,9 @@ function initSocket(self) { self._writeWatcher.socket = self; self._writeWatcher.callback = onWritable; self.writable = false; + + self.bytesRead = 0; + self.bytesWritten = 0; } // Deprecated API: Socket(fd, type) @@ -454,6 +457,8 @@ Socket.prototype._writeOut = function(data, encoding, fd, cb) { return false; } + this.bytesWritten += bytesWritten; + debug('wrote ' + bytesWritten + ' bytes to socket.') debug('[fd, off, len] = ' + JSON.stringify([this.fd, off, len])); @@ -664,6 +669,7 @@ Socket.prototype._onReadable = function() { var start = pool.used; var end = pool.used + bytesRead; pool.used += bytesRead; + self.bytesRead += bytesRead; debug('socket ' + self.fd + ' received ' + bytesRead + ' bytes'); diff --git a/lib/net_uv.js b/lib/net_uv.js index d45346e6f3e..e87b90529d2 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -51,6 +51,8 @@ function initSocketHandle(self) { self._flags = 0; self._connectQueueSize = 0; self.destroyed = false; + self.bytesRead = 0; + self.bytesWritten = 0; // Handle creation may be deferred to bind() or connect() time. if (self._handle) { @@ -255,6 +257,8 @@ function onread(buffer, offset, length) { } } + self.bytesRead += length; + // Optimization: emit the original buffer with end points if (self.ondata) self.ondata(buffer, offset, end); @@ -308,6 +312,8 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) { } } + this.bytesWritten += data.length; + // Change strings to buffers. SLOW if (typeof data == 'string') { data = new Buffer(data, encoding); |