@@ -97,7 +97,6 @@ exports._normalizeConnectArgs = normalizeConnectArgs;
97
97
// called when creating new Socket, or when re-using a closed Socket
98
98
function initSocketHandle ( self ) {
99
99
self . destroyed = false ;
100
- self . bytesRead = 0 ;
101
100
self . _bytesDispatched = 0 ;
102
101
self . _sockname = null ;
103
102
@@ -112,6 +111,10 @@ function initSocketHandle(self) {
112
111
}
113
112
}
114
113
114
+
115
+ const BYTES_READ = Symbol ( 'bytesRead' ) ;
116
+
117
+
115
118
function Socket ( options ) {
116
119
if ( ! ( this instanceof Socket ) ) return new Socket ( options ) ;
117
120
@@ -179,6 +182,9 @@ function Socket(options) {
179
182
// Reserve properties
180
183
this . server = null ;
181
184
this . _server = null ;
185
+
186
+ // Used after `.destroy()`
187
+ this [ BYTES_READ ] = 0 ;
182
188
}
183
189
util . inherits ( Socket , stream . Duplex ) ;
184
190
@@ -470,6 +476,9 @@ Socket.prototype._destroy = function(exception, cb) {
470
476
if ( this !== process . stderr )
471
477
debug ( 'close handle' ) ;
472
478
var isException = exception ? true : false ;
479
+ // `bytesRead` should be accessible after `.destroy()`
480
+ this [ BYTES_READ ] = this . _handle . bytesRead ;
481
+
473
482
this . _handle . close ( ( ) => {
474
483
debug ( 'emit close' ) ;
475
484
this . emit ( 'close' , isException ) ;
@@ -521,10 +530,6 @@ function onread(nread, buffer) {
521
530
// will prevent this from being called again until _read() gets
522
531
// called again.
523
532
524
- // if it's not enough data, we'll just call handle.readStart()
525
- // again right away.
526
- self . bytesRead += nread ;
527
-
528
533
// Optimization: emit the original buffer with end points
529
534
var ret = self . push ( buffer ) ;
530
535
@@ -580,6 +585,9 @@ Socket.prototype._getpeername = function() {
580
585
return this . _peername ;
581
586
} ;
582
587
588
+ Socket . prototype . __defineGetter__ ( 'bytesRead' , function ( ) {
589
+ return this . _handle ? this . _handle . bytesRead : this [ BYTES_READ ] ;
590
+ } ) ;
583
591
584
592
Socket . prototype . __defineGetter__ ( 'remoteAddress' , function ( ) {
585
593
return this . _getpeername ( ) . address ;
0 commit comments