@@ -2601,59 +2601,45 @@ class QuicStream extends Duplex {
2601
2601
this . _readableState . readingMore = true ;
2602
2602
this . on ( 'pause' , streamOnPause ) ;
2603
2603
2604
- // See src/node_quic_stream.h for an explanation
2605
- // of the initial states for unidirectional streams.
2606
- if ( this . unidirectional ) {
2607
- if ( session instanceof QuicServerSession ) {
2608
- if ( this . serverInitiated ) {
2609
- // Close the readable side
2610
- this . push ( null ) ;
2611
- this . read ( ) ;
2612
- } else {
2613
- // Close the writable side
2614
- this . end ( ) ;
2615
- }
2616
- } else if ( this . serverInitiated ) {
2617
- // Close the writable side
2618
- this . end ( ) ;
2619
- } else {
2620
- this . push ( null ) ;
2621
- this . read ( ) ;
2622
- }
2623
- }
2624
-
2625
2604
// The QuicStream writes are corked until kSetHandle
2626
2605
// is set, ensuring that writes are buffered in JavaScript
2627
2606
// until we have somewhere to send them.
2628
2607
this . cork ( ) ;
2629
2608
}
2630
2609
2631
- // Set handle is called once the QuicSession has been able
2632
- // to complete creation of the internal QuicStream handle.
2633
- // This will happen only after the QuicSession's own
2634
- // internal handle has been created. The QuicStream object
2635
- // is still minimally usable before this but any data
2636
- // written will be buffered until kSetHandle is called.
2637
- [ kSetHandle ] ( handle ) {
2638
- this [ kHandle ] = handle ;
2639
- if ( handle !== undefined ) {
2640
- handle . onread = onStreamRead ;
2641
- handle [ owner_symbol ] = this ;
2642
- this [ async_id_symbol ] = handle . getAsyncId ( ) ;
2643
- this . #id = handle . id ( ) ;
2644
- this . #dataRateHistogram = new Histogram ( handle . rate ) ;
2645
- this . #dataSizeHistogram = new Histogram ( handle . size ) ;
2646
- this . #dataAckHistogram = new Histogram ( handle . ack ) ;
2647
- this . uncork ( ) ;
2648
- this . emit ( 'ready' ) ;
2649
- } else {
2650
- if ( this . #dataRateHistogram)
2651
- this . #dataRateHistogram[ kDestroyHistogram ] ( ) ;
2652
- if ( this . #dataSizeHistogram)
2653
- this . #dataSizeHistogram[ kDestroyHistogram ] ( ) ;
2654
- if ( this . #dataAckHistogram)
2655
- this . #dataAckHistogram[ kDestroyHistogram ] ( ) ;
2656
- }
2610
+ _construct ( cb ) {
2611
+ // Set handle is called once the QuicSession has been able
2612
+ // to complete creation of the internal QuicStream handle.
2613
+ // This will happen only after the QuicSession's own
2614
+ // internal handle has been created. The QuicStream object
2615
+ // is still minimally usable before this but any data
2616
+ // written will be buffered until kSetHandle is called.
2617
+ this [ kSetHandle ] = ( handle ) => {
2618
+ this [ kHandle ] = handle ;
2619
+ if ( handle !== undefined ) {
2620
+ handle . onread = onStreamRead ;
2621
+ handle [ owner_symbol ] = this ;
2622
+ this [ async_id_symbol ] = handle . getAsyncId ( ) ;
2623
+ this . #id = handle . id ( ) ;
2624
+ this . #dataRateHistogram = new Histogram ( handle . rate ) ;
2625
+ this . #dataSizeHistogram = new Histogram ( handle . size ) ;
2626
+ this . #dataAckHistogram = new Histogram ( handle . ack ) ;
2627
+ this . uncork ( ) ;
2628
+
2629
+ this . emit ( 'ready' ) ;
2630
+ // TODO (fix): What happens on failure? We still need to
2631
+ // invoke the callback somehow? Change signature of kSetHandle
2632
+ // to (err, handle)?
2633
+ cb ( ) ;
2634
+ } else {
2635
+ if ( this . #dataRateHistogram)
2636
+ this . #dataRateHistogram[ kDestroyHistogram ] ( ) ;
2637
+ if ( this . #dataSizeHistogram)
2638
+ this . #dataSizeHistogram[ kDestroyHistogram ] ( ) ;
2639
+ if ( this . #dataAckHistogram)
2640
+ this . #dataAckHistogram[ kDestroyHistogram ] ( ) ;
2641
+ }
2642
+ } ;
2657
2643
}
2658
2644
2659
2645
[ kStreamReset ] ( code ) {
@@ -2700,6 +2686,7 @@ class QuicStream extends Duplex {
2700
2686
if ( this . destroyed || this . #closed)
2701
2687
return ;
2702
2688
2689
+ // TODO: This will deadlock on failure?
2703
2690
if ( this . pending )
2704
2691
return this . once ( 'ready' , ( ) => this [ kClose ] ( family , code ) ) ;
2705
2692
@@ -2785,19 +2772,6 @@ class QuicStream extends Duplex {
2785
2772
}
2786
2773
2787
2774
#writeGeneric = function ( writev , data , encoding , cb ) {
2788
- if ( this . destroyed )
2789
- return ; // TODO(addaleax): Can this happen?
2790
-
2791
- // The stream should be corked while still pending
2792
- // but just in case uncork
2793
- // was called early, defer the actual write until the
2794
- // ready event is emitted.
2795
- if ( this . pending ) {
2796
- return this . once ( 'ready' , ( ) => {
2797
- this . #writeGeneric( writev , data , encoding , cb ) ;
2798
- } ) ;
2799
- }
2800
-
2801
2775
this [ kUpdateTimer ] ( ) ;
2802
2776
const req = ( writev ) ?
2803
2777
writevGeneric ( this , data , cb ) :
@@ -2821,13 +2795,6 @@ class QuicStream extends Duplex {
2821
2795
// coming so that a fin stream packet can be
2822
2796
// sent.
2823
2797
_final ( cb ) {
2824
- // The QuicStream should be corked while pending
2825
- // so this shouldn't be called, but just in case
2826
- // the stream was prematurely uncorked, defer the
2827
- // operation until the ready event is emitted.
2828
- if ( this . pending )
2829
- return this . once ( 'ready' , ( ) => this . _final ( cb ) ) ;
2830
-
2831
2798
const handle = this [ kHandle ] ;
2832
2799
if ( handle === undefined ) {
2833
2800
cb ( ) ;
@@ -2840,16 +2807,10 @@ class QuicStream extends Duplex {
2840
2807
const err = handle . shutdown ( req ) ;
2841
2808
if ( err === 1 )
2842
2809
return cb ( ) ;
2810
+ // TODO (fix): else if (err !== 0)?
2843
2811
}
2844
2812
2845
2813
_read ( nread ) {
2846
- if ( this . pending )
2847
- return this . once ( 'ready' , ( ) => this . _read ( nread ) ) ;
2848
-
2849
- if ( this . destroyed ) { // TODO(addaleax): Can this happen?
2850
- this . push ( null ) ;
2851
- return ;
2852
- }
2853
2814
if ( ! this . #didRead) {
2854
2815
this . _readableState . readingMore = false ;
2855
2816
this . #didRead = true ;
@@ -2895,6 +2856,7 @@ class QuicStream extends Duplex {
2895
2856
throw new ERR_INVALID_ARG_TYPE ( 'fd' , [ 'number' , 'FileHandle' ] , fd ) ;
2896
2857
2897
2858
if ( this . pending ) {
2859
+ // TODO: This will deadlock on failure?
2898
2860
return this . once ( 'ready' , ( ) => {
2899
2861
this . sendFD ( fd , { offset, length } , ownsFd ) ;
2900
2862
} ) ;
0 commit comments