@@ -124,7 +124,7 @@ OutgoingMessage.prototype._send = function(data, encoding, callback) {
124
124
this . outputEncodings . unshift ( 'binary' ) ;
125
125
this . outputCallbacks . unshift ( null ) ;
126
126
this . outputSize += this . _header . length ;
127
- if ( this . _onPendingData !== null )
127
+ if ( typeof this . _onPendingData === 'function' )
128
128
this . _onPendingData ( this . _header . length ) ;
129
129
}
130
130
this . _headerSent = true ;
@@ -147,20 +147,7 @@ OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) {
147
147
// There might be pending data in the this.output buffer.
148
148
var outputLength = this . output . length ;
149
149
if ( outputLength > 0 ) {
150
- var output = this . output ;
151
- var outputEncodings = this . outputEncodings ;
152
- var outputCallbacks = this . outputCallbacks ;
153
- for ( var i = 0 ; i < outputLength ; i ++ ) {
154
- connection . write ( output [ i ] , outputEncodings [ i ] ,
155
- outputCallbacks [ i ] ) ;
156
- }
157
-
158
- this . output = [ ] ;
159
- this . outputEncodings = [ ] ;
160
- this . outputCallbacks = [ ] ;
161
- if ( this . _onPendingData !== null )
162
- this . _onPendingData ( - this . outputSize ) ;
163
- this . outputSize = 0 ;
150
+ this . _flushOutput ( connection ) ;
164
151
} else if ( data . length === 0 ) {
165
152
if ( typeof callback === 'function' )
166
153
process . nextTick ( callback ) ;
@@ -185,7 +172,7 @@ OutgoingMessage.prototype._buffer = function(data, encoding, callback) {
185
172
this . outputEncodings . push ( encoding ) ;
186
173
this . outputCallbacks . push ( callback ) ;
187
174
this . outputSize += data . length ;
188
- if ( this . _onPendingData !== null )
175
+ if ( typeof this . _onPendingData === 'function' )
189
176
this . _onPendingData ( data . length ) ;
190
177
return false ;
191
178
} ;
@@ -618,24 +605,11 @@ OutgoingMessage.prototype._finish = function() {
618
605
// to attempt to flush any pending messages out to the socket.
619
606
OutgoingMessage . prototype . _flush = function ( ) {
620
607
var socket = this . socket ;
621
- var outputLength , ret ;
608
+ var ret ;
622
609
623
610
if ( socket && socket . writable ) {
624
611
// There might be remaining data in this.output; write it out
625
- outputLength = this . output . length ;
626
- if ( outputLength > 0 ) {
627
- var output = this . output ;
628
- var outputEncodings = this . outputEncodings ;
629
- var outputCallbacks = this . outputCallbacks ;
630
- for ( var i = 0 ; i < outputLength ; i ++ ) {
631
- ret = socket . write ( output [ i ] , outputEncodings [ i ] ,
632
- outputCallbacks [ i ] ) ;
633
- }
634
-
635
- this . output = [ ] ;
636
- this . outputEncodings = [ ] ;
637
- this . outputCallbacks = [ ] ;
638
- }
612
+ ret = this . _flushOutput ( socket ) ;
639
613
640
614
if ( this . finished ) {
641
615
// This is a queue to the server or client to bring in the next this.
@@ -647,6 +621,32 @@ OutgoingMessage.prototype._flush = function() {
647
621
}
648
622
} ;
649
623
624
+ OutgoingMessage . prototype . _flushOutput = function _flushOutput ( socket ) {
625
+ var ret ;
626
+ var outputLength = this . output . length ;
627
+ if ( outputLength <= 0 )
628
+ return ret ;
629
+
630
+ var output = this . output ;
631
+ var outputEncodings = this . outputEncodings ;
632
+ var outputCallbacks = this . outputCallbacks ;
633
+ socket . cork ( ) ;
634
+ for ( var i = 0 ; i < outputLength ; i ++ ) {
635
+ ret = socket . write ( output [ i ] , outputEncodings [ i ] ,
636
+ outputCallbacks [ i ] ) ;
637
+ }
638
+ socket . uncork ( ) ;
639
+
640
+ this . output = [ ] ;
641
+ this . outputEncodings = [ ] ;
642
+ this . outputCallbacks = [ ] ;
643
+ if ( typeof this . _onPendingData === 'function' )
644
+ this . _onPendingData ( - this . outputSize ) ;
645
+ this . outputSize = 0 ;
646
+
647
+ return ret ;
648
+ } ;
649
+
650
650
651
651
OutgoingMessage . prototype . flushHeaders = function ( ) {
652
652
if ( ! this . _header ) {
0 commit comments