@@ -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
@@ -472,6 +478,9 @@ Socket.prototype._destroy = function(exception, cb) {
472478 if ( this !== process . stderr )
473479 debug ( 'close handle' ) ;
474480 var isException = exception ? true : false ;
481+ // `bytesRead` should be accessible after `.destroy()`
482+ this [ BYTES_READ ] = this . _handle . bytesRead ;
483+
475484 this . _handle . close ( function ( ) {
476485 debug ( 'emit close' ) ;
477486 self . emit ( 'close' , isException ) ;
@@ -523,10 +532,6 @@ function onread(nread, buffer) {
523532 // will prevent this from being called again until _read() gets
524533 // called again.
525534
526- // if it's not enough data, we'll just call handle.readStart()
527- // again right away.
528- self . bytesRead += nread ;
529-
530535 // Optimization: emit the original buffer with end points
531536 var ret = self . push ( buffer ) ;
532537
@@ -582,6 +587,9 @@ Socket.prototype._getpeername = function() {
582587 return this . _peername ;
583588} ;
584589
590+ Socket . prototype . __defineGetter__ ( 'bytesRead' , function ( ) {
591+ return this . _handle ? this . _handle . bytesRead : this [ BYTES_READ ] ;
592+ } ) ;
585593
586594Socket . prototype . __defineGetter__ ( 'remoteAddress' , function ( ) {
587595 return this . _getpeername ( ) . address ;
0 commit comments