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