@@ -88,6 +88,7 @@ const kUniqueHeaders = Symbol('kUniqueHeaders');
88
88
const kBytesWritten = Symbol ( 'kBytesWritten' ) ;
89
89
const kEndCalled = Symbol ( 'kEndCalled' ) ;
90
90
const kErrored = Symbol ( 'errored' ) ;
91
+ const kSocket = Symbol ( 'kSocket' ) ;
91
92
92
93
const nop = ( ) => { } ;
93
94
@@ -188,22 +189,21 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableObjectMode', {
188
189
ObjectDefineProperty ( OutgoingMessage . prototype , 'writableLength' , {
189
190
__proto__ : null ,
190
191
get ( ) {
191
- return this . outputSize + ( this . socket ? this . socket . writableLength : 0 ) ;
192
+ return this . outputSize + ( this [ kSocket ] ? this [ kSocket ] . writableLength : 0 ) ;
192
193
}
193
194
} ) ;
194
195
195
196
ObjectDefineProperty ( OutgoingMessage . prototype , 'writableHighWaterMark' , {
196
197
__proto__ : null ,
197
198
get ( ) {
198
- return this . socket ? this . socket . writableHighWaterMark : HIGH_WATER_MARK ;
199
+ return this [ kSocket ] ? this [ kSocket ] . writableHighWaterMark : HIGH_WATER_MARK ;
199
200
}
200
201
} ) ;
201
202
202
203
ObjectDefineProperty ( OutgoingMessage . prototype , 'writableCorked' , {
203
204
__proto__ : null ,
204
205
get ( ) {
205
- const corked = this . socket ? this . socket . writableCorked : 0 ;
206
- return corked + this [ kCorked ] ;
206
+ return this [ kSocket ] ? this [ kSocket ] . writableCorked : this [ kCorked ] ;
207
207
}
208
208
} ) ;
209
209
@@ -238,6 +238,20 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'connection', {
238
238
}
239
239
} ) ;
240
240
241
+ ObjectDefineProperty ( OutgoingMessage . prototype , 'socket' , {
242
+ __proto__ : null ,
243
+ get : function ( ) {
244
+ return this [ kSocket ] ;
245
+ } ,
246
+ set : function ( val ) {
247
+ for ( let n = 0 ; n < this [ kCorked ] ; n ++ ) {
248
+ val ?. cork ( ) ;
249
+ }
250
+ this [ kCorked ] = 0 ;
251
+ this [ kSocket ] = val ;
252
+ }
253
+ } ) ;
254
+
241
255
ObjectDefineProperty ( OutgoingMessage . prototype , '_headerNames' , {
242
256
__proto__ : null ,
243
257
get : internalUtil . deprecate ( function ( ) {
@@ -916,8 +930,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
916
930
}
917
931
918
932
if ( ! fromEnd && msg . socket && ! msg . socket . writableCorked ) {
919
- msg . socket . cork ( ) ;
920
- process . nextTick ( connectionCorkNT , msg . socket ) ;
933
+ msg . cork ( ) ;
934
+ process . nextTick ( connectionUncorkNT , msg ) ;
921
935
}
922
936
923
937
let ret ;
@@ -935,8 +949,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
935
949
}
936
950
937
951
938
- function connectionCorkNT ( conn ) {
939
- conn . uncork ( ) ;
952
+ function connectionUncorkNT ( msg ) {
953
+ msg . uncork ( ) ;
940
954
}
941
955
942
956
OutgoingMessage . prototype . addTrailers = function addTrailers ( headers ) {
@@ -1049,8 +1063,9 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
1049
1063
// Fully uncork connection on end().
1050
1064
this . socket . _writableState . corked = 1 ;
1051
1065
this . socket . uncork ( ) ;
1066
+ } else {
1067
+ this [ kCorked ] = 0 ;
1052
1068
}
1053
- this [ kCorked ] = 0 ;
1054
1069
1055
1070
this . finished = true ;
1056
1071
@@ -1112,11 +1127,6 @@ OutgoingMessage.prototype._flush = function _flush() {
1112
1127
} ;
1113
1128
1114
1129
OutgoingMessage . prototype . _flushOutput = function _flushOutput ( socket ) {
1115
- while ( this [ kCorked ] ) {
1116
- this [ kCorked ] -- ;
1117
- socket . cork ( ) ;
1118
- }
1119
-
1120
1130
const outputLength = this . outputData . length ;
1121
1131
if ( outputLength <= 0 )
1122
1132
return undefined ;
0 commit comments