aboutsummaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-04-19 14:46:53 -0400
committerFedor Indutny <fedor@indutny.com>2016-04-20 12:42:33 -0400
commit6198472d8390d9476f555c634b7aa66ce6c6d0fe (patch)
tree506f7b4824a8754ff2645b49077e918af627386b /lib/net.js
parente1cf634a0bd0cae2b54c60c8f19fc29079bdc309 (diff)
downloadandroid-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.gz
android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.bz2
android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.zip
stream_base: expose `bytesRead` getter
This will provide `bytesRead` data on consumed sockets. Fix: #3021 PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/net.js b/lib/net.js
index e92ec369e5..e3b726a756 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -97,7 +97,6 @@ exports._normalizeConnectArgs = normalizeConnectArgs;
// called when creating new Socket, or when re-using a closed Socket
function initSocketHandle(self) {
self.destroyed = false;
- self.bytesRead = 0;
self._bytesDispatched = 0;
self._sockname = null;
@@ -112,6 +111,10 @@ function initSocketHandle(self) {
}
}
+
+const BYTES_READ = Symbol('bytesRead');
+
+
function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);
@@ -179,6 +182,9 @@ function Socket(options) {
// Reserve properties
this.server = null;
this._server = null;
+
+ // Used after `.destroy()`
+ this[BYTES_READ] = 0;
}
util.inherits(Socket, stream.Duplex);
@@ -470,6 +476,9 @@ Socket.prototype._destroy = function(exception, cb) {
if (this !== process.stderr)
debug('close handle');
var isException = exception ? true : false;
+ // `bytesRead` should be accessible after `.destroy()`
+ this[BYTES_READ] = this._handle.bytesRead;
+
this._handle.close(() => {
debug('emit close');
this.emit('close', isException);
@@ -521,10 +530,6 @@ function onread(nread, buffer) {
// will prevent this from being called again until _read() gets
// called again.
- // if it's not enough data, we'll just call handle.readStart()
- // again right away.
- self.bytesRead += nread;
-
// Optimization: emit the original buffer with end points
var ret = self.push(buffer);
@@ -580,6 +585,9 @@ Socket.prototype._getpeername = function() {
return this._peername;
};
+Socket.prototype.__defineGetter__('bytesRead', function() {
+ return this._handle ? this._handle.bytesRead : this[BYTES_READ];
+});
Socket.prototype.__defineGetter__('remoteAddress', function() {
return this._getpeername().address;