@@ -547,15 +547,34 @@ Connection.prototype.input = function (buff) {
547547 try {
548548 if ( this . heartbeat_in ) clearTimeout ( this . heartbeat_in ) ;
549549 log . io ( '[%s] read %d bytes' , this . options . id , buff . length ) ;
550- if ( this . previous_input ) {
551- buffer = Buffer . concat ( [ this . previous_input , buff ] , this . previous_input . length + buff . length ) ;
550+ if ( this . frame_size ) {
551+ this . received_bytes += buff . length ;
552+ this . chunks . push ( buff ) ;
553+ if ( this . frame_size <= this . received_bytes ) {
554+ buffer = Buffer . concat ( this . chunks , this . received_bytes ) ;
555+ this . chunks = null ;
556+ this . frame_size = undefined ;
557+ } else {
558+ log . io ( '[%s] pushed %d bytes' , this . options . id , buff . length ) ;
559+ return ;
560+ }
561+ } else if ( this . previous_input ) {
562+ buffer = Buffer . concat ( [ this . previous_input , buff ] ) ;
552563 this . previous_input = null ;
553564 } else {
554565 buffer = buff ;
555566 }
556- var read = this . transport . read ( buffer , this ) ;
567+ const read = this . transport . read ( buffer , this ) ;
557568 if ( read < buffer . length ) {
558- this . previous_input = buffer . slice ( read ) ;
569+ const previous_input = buffer . slice ( read ) ;
570+ this . frame_size = this . transport . peek_size ( previous_input ) ;
571+ if ( this . frame_size ) {
572+ this . chunks = [ previous_input ] ;
573+ this . received_bytes = previous_input . length ;
574+ log . io ( '[%s] waiting frame_size %s' , this . options . id , this . frame_size ) ;
575+ } else {
576+ this . previous_input = previous_input ;
577+ }
559578 }
560579 if ( this . local . open . idle_time_out ) this . heartbeat_in = setTimeout ( this . idle . bind ( this ) , this . local . open . idle_time_out ) ;
561580 if ( this . transport . has_writes_pending ( ) ) {
0 commit comments