@@ -36,8 +36,7 @@ const {
3636const assert = require ( 'assert' ) ;
3737const {
3838 UV_EADDRINUSE ,
39- UV_EINVAL ,
40- UV_EOF
39+ UV_EINVAL
4140} = process . binding ( 'uv' ) ;
4241
4342const { Buffer } = require ( 'buffer' ) ;
@@ -61,7 +60,9 @@ const {
6160const {
6261 createWriteWrap,
6362 writevGeneric,
64- writeGeneric
63+ writeGeneric,
64+ onStreamRead,
65+ kUpdateTimer
6566} = require ( 'internal/stream_base_commons' ) ;
6667const errors = require ( 'internal/errors' ) ;
6768const {
@@ -208,7 +209,7 @@ function initSocketHandle(self) {
208209 // Handle creation may be deferred to bind() or connect() time.
209210 if ( self . _handle ) {
210211 self . _handle [ owner_symbol ] = self ;
211- self . _handle . onread = onread ;
212+ self . _handle . onread = onStreamRead ;
212213 self [ async_id_symbol ] = getNewAsyncId ( self . _handle ) ;
213214 }
214215}
@@ -514,6 +515,12 @@ Object.defineProperty(Socket.prototype, 'bufferSize', {
514515 }
515516} ) ;
516517
518+ Object . defineProperty ( Socket . prototype , kUpdateTimer , {
519+ get : function ( ) {
520+ return this . _unrefTimer ;
521+ }
522+ } ) ;
523+
517524
518525// Just call handle.readStart until we have enough in the buffer
519526Socket . prototype . _read = function ( n ) {
@@ -615,61 +622,6 @@ Socket.prototype._destroy = function(exception, cb) {
615622 }
616623} ;
617624
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-
673625Socket . prototype . _getpeername = function ( ) {
674626 if ( ! this . _peername ) {
675627 if ( ! this . _handle || ! this . _handle . getpeername ) {
0 commit comments