@@ -97,7 +97,6 @@ exports._normalizeConnectArgs = normalizeConnectArgs;
9797// called when creating new Socket, or when re-using a closed Socket
9898function initSocketHandle ( self ) {
9999 self . destroyed = false ;
100- self . bytesRead = 0 ;
101100 self . _bytesDispatched = 0 ;
102101 self . _sockname = null ;
103102
@@ -112,6 +111,10 @@ function initSocketHandle(self) {
112111 }
113112}
114113
114+
115+ const BYTES_READ = Symbol ( 'bytesRead' ) ;
116+
117+
115118function Socket ( options ) {
116119 if ( ! ( this instanceof Socket ) ) return new Socket ( options ) ;
117120
@@ -179,6 +182,9 @@ function Socket(options) {
179182 // Reserve properties
180183 this . server = null ;
181184 this . _server = null ;
185+
186+ // Used after `.destroy()`
187+ this [ BYTES_READ ] = 0 ;
182188}
183189util . inherits ( Socket , stream . Duplex ) ;
184190
@@ -470,6 +476,9 @@ Socket.prototype._destroy = function(exception, cb) {
470476 if ( this !== process . stderr )
471477 debug ( 'close handle' ) ;
472478 var isException = exception ? true : false ;
479+ // `bytesRead` should be accessible after `.destroy()`
480+ this [ BYTES_READ ] = this . _handle . bytesRead ;
481+
473482 this . _handle . close ( ( ) => {
474483 debug ( 'emit close' ) ;
475484 this . emit ( 'close' , isException ) ;
@@ -521,10 +530,6 @@ function onread(nread, buffer) {
521530 // will prevent this from being called again until _read() gets
522531 // called again.
523532
524- // if it's not enough data, we'll just call handle.readStart()
525- // again right away.
526- self . bytesRead += nread ;
527-
528533 // Optimization: emit the original buffer with end points
529534 var ret = self . push ( buffer ) ;
530535
@@ -580,6 +585,9 @@ Socket.prototype._getpeername = function() {
580585 return this . _peername ;
581586} ;
582587
588+ Socket . prototype . __defineGetter__ ( 'bytesRead' , function ( ) {
589+ return this . _handle ? this . _handle . bytesRead : this [ BYTES_READ ] ;
590+ } ) ;
583591
584592Socket . prototype . __defineGetter__ ( 'remoteAddress' , function ( ) {
585593 return this . _getpeername ( ) . address ;
0 commit comments