@@ -36,8 +36,7 @@ const {
36
36
const assert = require ( 'assert' ) ;
37
37
const {
38
38
UV_EADDRINUSE ,
39
- UV_EINVAL ,
40
- UV_EOF
39
+ UV_EINVAL
41
40
} = process . binding ( 'uv' ) ;
42
41
43
42
const { Buffer } = require ( 'buffer' ) ;
@@ -61,7 +60,9 @@ const {
61
60
const {
62
61
createWriteWrap,
63
62
writevGeneric,
64
- writeGeneric
63
+ writeGeneric,
64
+ onStreamRead,
65
+ kUpdateTimer
65
66
} = require ( 'internal/stream_base_commons' ) ;
66
67
const errors = require ( 'internal/errors' ) ;
67
68
const {
@@ -208,7 +209,7 @@ function initSocketHandle(self) {
208
209
// Handle creation may be deferred to bind() or connect() time.
209
210
if ( self . _handle ) {
210
211
self . _handle [ owner_symbol ] = self ;
211
- self . _handle . onread = onread ;
212
+ self . _handle . onread = onStreamRead ;
212
213
self [ async_id_symbol ] = getNewAsyncId ( self . _handle ) ;
213
214
}
214
215
}
@@ -514,6 +515,12 @@ Object.defineProperty(Socket.prototype, 'bufferSize', {
514
515
}
515
516
} ) ;
516
517
518
+ Object . defineProperty ( Socket . prototype , kUpdateTimer , {
519
+ get : function ( ) {
520
+ return this . _unrefTimer ;
521
+ }
522
+ } ) ;
523
+
517
524
518
525
// Just call handle.readStart until we have enough in the buffer
519
526
Socket . prototype . _read = function ( n ) {
@@ -615,61 +622,6 @@ Socket.prototype._destroy = function(exception, cb) {
615
622
}
616
623
} ;
617
624
618
-
619
- // This function is called whenever the handle gets a
620
- // buffer, or when there's an error reading.
621
- function onread ( nread , buffer ) {
622
- var handle = this ;
623
- var self = handle [ owner_symbol ] ;
624
- assert ( handle === self . _handle , 'handle != self._handle' ) ;
625
-
626
- self . _unrefTimer ( ) ;
627
-
628
- debug ( 'onread' , nread ) ;
629
-
630
- if ( nread > 0 ) {
631
- debug ( 'got data' ) ;
632
-
633
- // read success.
634
- // In theory (and in practice) calling readStop right now
635
- // will prevent this from being called again until _read() gets
636
- // called again.
637
-
638
- // Optimization: emit the original buffer with end points
639
- var ret = self . push ( buffer ) ;
640
-
641
- if ( handle . reading && ! ret ) {
642
- handle . reading = false ;
643
- debug ( 'readStop' ) ;
644
- var err = handle . readStop ( ) ;
645
- if ( err )
646
- self . destroy ( errnoException ( err , 'read' ) ) ;
647
- }
648
- return ;
649
- }
650
-
651
- // if we didn't get any bytes, that doesn't necessarily mean EOF.
652
- // wait for the next one.
653
- if ( nread === 0 ) {
654
- debug ( 'not any data, keep waiting' ) ;
655
- return ;
656
- }
657
-
658
- // Error, possibly EOF.
659
- if ( nread !== UV_EOF ) {
660
- return self . destroy ( errnoException ( nread , 'read' ) ) ;
661
- }
662
-
663
- debug ( 'EOF' ) ;
664
-
665
- // push a null to signal the end of data.
666
- // Do it before `maybeDestroy` for correct order of events:
667
- // `end` -> `close`
668
- self . push ( null ) ;
669
- self . read ( 0 ) ;
670
- }
671
-
672
-
673
625
Socket . prototype . _getpeername = function ( ) {
674
626
if ( ! this . _peername ) {
675
627
if ( ! this . _handle || ! this . _handle . getpeername ) {
0 commit comments