@@ -146,6 +146,7 @@ const kSession = Symbol('session');
146
146
const kState = Symbol ( 'state' ) ;
147
147
const kType = Symbol ( 'type' ) ;
148
148
const kUpdateTimer = Symbol ( 'update-timer' ) ;
149
+ const kWriteGeneric = Symbol ( 'write-generic' ) ;
149
150
150
151
const kDefaultSocketTimeout = 2 * 60 * 1000 ;
151
152
@@ -1657,13 +1658,16 @@ class Http2Stream extends Duplex {
1657
1658
'bug in Node.js' ) ;
1658
1659
}
1659
1660
1660
- _write ( data , encoding , cb ) {
1661
+ [ kWriteGeneric ] ( writev , data , encoding , cb ) {
1661
1662
// When the Http2Stream is first created, it is corked until the
1662
1663
// handle and the stream ID is assigned. However, if the user calls
1663
1664
// uncork() before that happens, the Duplex will attempt to pass
1664
1665
// writes through. Those need to be queued up here.
1665
1666
if ( this . pending ) {
1666
- this . once ( 'ready' , this . _write . bind ( this , data , encoding , cb ) ) ;
1667
+ this . once (
1668
+ 'ready' ,
1669
+ this [ kWriteGeneric ] . bind ( this , writev , data , encoding , cb )
1670
+ ) ;
1667
1671
return ;
1668
1672
}
1669
1673
@@ -1683,41 +1687,20 @@ class Http2Stream extends Duplex {
1683
1687
const req = createWriteWrap ( this [ kHandle ] , afterDoStreamWrite ) ;
1684
1688
req . stream = this [ kID ] ;
1685
1689
1686
- writeGeneric ( this , req , data , encoding , cb ) ;
1690
+ if ( writev )
1691
+ writevGeneric ( this , req , data , cb ) ;
1692
+ else
1693
+ writeGeneric ( this , req , data , encoding , cb ) ;
1687
1694
1688
1695
trackWriteState ( this , req . bytes ) ;
1689
1696
}
1690
1697
1691
- _writev ( data , cb ) {
1692
- // When the Http2Stream is first created, it is corked until the
1693
- // handle and the stream ID is assigned. However, if the user calls
1694
- // uncork() before that happens, the Duplex will attempt to pass
1695
- // writes through. Those need to be queued up here.
1696
- if ( this . pending ) {
1697
- this . once ( 'ready' , this . _writev . bind ( this , data , cb ) ) ;
1698
- return ;
1699
- }
1700
-
1701
- // If the stream has been destroyed, there's nothing else we can do
1702
- // because the handle has been destroyed. This should only be an
1703
- // issue if a write occurs before the 'ready' event in the case where
1704
- // the duplex is uncorked before the stream is ready to go. In that
1705
- // case, drop the data on the floor. An error should have already been
1706
- // emitted.
1707
- if ( this . destroyed )
1708
- return ;
1709
-
1710
- this [ kUpdateTimer ] ( ) ;
1711
-
1712
- if ( ! this . headersSent )
1713
- this [ kProceed ] ( ) ;
1714
-
1715
- var req = createWriteWrap ( this [ kHandle ] , afterDoStreamWrite ) ;
1716
- req . stream = this [ kID ] ;
1717
-
1718
- writevGeneric ( this , req , data , cb ) ;
1698
+ _write ( data , encoding , cb ) {
1699
+ this [ kWriteGeneric ] ( false , data , encoding , cb ) ;
1700
+ }
1719
1701
1720
- trackWriteState ( this , req . bytes ) ;
1702
+ _writev ( data , cb ) {
1703
+ this [ kWriteGeneric ] ( true , data , '' , cb ) ;
1721
1704
}
1722
1705
1723
1706
_final ( cb ) {
0 commit comments