@@ -95,6 +95,7 @@ const kSession = Symbol('session');
95
95
const kState = Symbol ( 'state' ) ;
96
96
const kType = Symbol ( 'type' ) ;
97
97
const kUpdateTimer = Symbol ( 'update-timer' ) ;
98
+ const kWriteGeneric = Symbol ( 'write-generic' ) ;
98
99
99
100
const kDefaultSocketTimeout = 2 * 60 * 1000 ;
100
101
@@ -1635,13 +1636,16 @@ class Http2Stream extends Duplex {
1635
1636
'bug in Node.js' ) ;
1636
1637
}
1637
1638
1638
- _write ( data , encoding , cb ) {
1639
+ [ kWriteGeneric ] ( writev , data , encoding , cb ) {
1639
1640
// When the Http2Stream is first created, it is corked until the
1640
1641
// handle and the stream ID is assigned. However, if the user calls
1641
1642
// uncork() before that happens, the Duplex will attempt to pass
1642
1643
// writes through. Those need to be queued up here.
1643
1644
if ( this . pending ) {
1644
- this . once ( 'ready' , this . _write . bind ( this , data , encoding , cb ) ) ;
1645
+ this . once (
1646
+ 'ready' ,
1647
+ this [ kWriteGeneric ] . bind ( this , writev , data , encoding , cb )
1648
+ ) ;
1645
1649
return ;
1646
1650
}
1647
1651
@@ -1665,53 +1669,30 @@ class Http2Stream extends Duplex {
1665
1669
req . callback = cb ;
1666
1670
req . oncomplete = afterDoStreamWrite ;
1667
1671
req . async = false ;
1668
- const err = createWriteReq ( req , handle , data , encoding ) ;
1672
+
1673
+ let err ;
1674
+ if ( writev ) {
1675
+ const chunks = new Array ( data . length << 1 ) ;
1676
+ for ( var i = 0 ; i < data . length ; i ++ ) {
1677
+ const entry = data [ i ] ;
1678
+ chunks [ i * 2 ] = entry . chunk ;
1679
+ chunks [ i * 2 + 1 ] = entry . encoding ;
1680
+ }
1681
+ err = handle . writev ( req , chunks ) ;
1682
+ } else {
1683
+ err = createWriteReq ( req , handle , data , encoding ) ;
1684
+ }
1669
1685
if ( err )
1670
1686
return this . destroy ( errors . errnoException ( err , 'write' , req . error ) , cb ) ;
1671
1687
trackWriteState ( this , req . bytes ) ;
1672
1688
}
1673
1689
1674
- _writev ( data , cb ) {
1675
- // When the Http2Stream is first created, it is corked until the
1676
- // handle and the stream ID is assigned. However, if the user calls
1677
- // uncork() before that happens, the Duplex will attempt to pass
1678
- // writes through. Those need to be queued up here.
1679
- if ( this . pending ) {
1680
- this . once ( 'ready' , this . _writev . bind ( this , data , cb ) ) ;
1681
- return ;
1682
- }
1683
-
1684
- // If the stream has been destroyed, there's nothing else we can do
1685
- // because the handle has been destroyed. This should only be an
1686
- // issue if a write occurs before the 'ready' event in the case where
1687
- // the duplex is uncorked before the stream is ready to go. In that
1688
- // case, drop the data on the floor. An error should have already been
1689
- // emitted.
1690
- if ( this . destroyed )
1691
- return ;
1692
-
1693
- this [ kUpdateTimer ] ( ) ;
1694
-
1695
- if ( ! this . headersSent )
1696
- this [ kProceed ] ( ) ;
1690
+ _write ( data , encoding , cb ) {
1691
+ this [ kWriteGeneric ] ( false , data , encoding , cb ) ;
1692
+ }
1697
1693
1698
- const handle = this [ kHandle ] ;
1699
- const req = new WriteWrap ( ) ;
1700
- req . stream = this [ kID ] ;
1701
- req . handle = handle ;
1702
- req . callback = cb ;
1703
- req . oncomplete = afterDoStreamWrite ;
1704
- req . async = false ;
1705
- const chunks = new Array ( data . length << 1 ) ;
1706
- for ( var i = 0 ; i < data . length ; i ++ ) {
1707
- const entry = data [ i ] ;
1708
- chunks [ i * 2 ] = entry . chunk ;
1709
- chunks [ i * 2 + 1 ] = entry . encoding ;
1710
- }
1711
- const err = handle . writev ( req , chunks ) ;
1712
- if ( err )
1713
- return this . destroy ( errors . errnoException ( err , 'write' , req . error ) , cb ) ;
1714
- trackWriteState ( this , req . bytes ) ;
1694
+ _writev ( data , cb ) {
1695
+ this [ kWriteGeneric ] ( true , data , '' , cb ) ;
1715
1696
}
1716
1697
1717
1698
_final ( cb ) {
0 commit comments