|
@ -525,38 +525,32 @@ OutgoingMessage.prototype._finish = function() { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This logic is probably a bit confusing. Let me explain a bit:
|
|
|
|
|
|
//
|
|
|
|
|
|
// In both HTTP servers and clients it is possible to queue up several
|
|
|
|
|
|
// outgoing messages. This is easiest to imagine in the case of a client.
|
|
|
|
|
|
// Take the following situation:
|
|
|
|
|
|
//
|
|
|
|
|
|
// req1 = client.request('GET', '/');
|
|
|
|
|
|
// req2 = client.request('POST', '/');
|
|
|
|
|
|
//
|
|
|
|
|
|
// When the user does
|
|
|
|
|
|
//
|
|
|
|
|
|
// req2.write('hello world\n');
|
|
|
|
|
|
//
|
|
|
|
|
|
// it's possible that the first request has not been completely flushed to
|
|
|
|
|
|
// the socket yet. Thus the outgoing messages need to be prepared to queue
|
|
|
|
|
|
// up data internally before sending it on further to the socket's queue.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This function, outgoingFlush(), is called by both the Server and Client
|
|
|
|
|
|
// to attempt to flush any pending messages out to the socket.
|
|
|
OutgoingMessage.prototype._flush = function() { |
|
|
OutgoingMessage.prototype._flush = function() { |
|
|
// This logic is probably a bit confusing. Let me explain a bit:
|
|
|
if (this.socket && this.socket.writable) { |
|
|
//
|
|
|
|
|
|
// In both HTTP servers and clients it is possible to queue up several
|
|
|
|
|
|
// outgoing messages. This is easiest to imagine in the case of a client.
|
|
|
|
|
|
// Take the following situation:
|
|
|
|
|
|
//
|
|
|
|
|
|
// req1 = client.request('GET', '/');
|
|
|
|
|
|
// req2 = client.request('POST', '/');
|
|
|
|
|
|
//
|
|
|
|
|
|
// When the user does
|
|
|
|
|
|
//
|
|
|
|
|
|
// req2.write('hello world\n');
|
|
|
|
|
|
//
|
|
|
|
|
|
// it's possible that the first request has not been completely flushed to
|
|
|
|
|
|
// the socket yet. Thus the outgoing messages need to be prepared to queue
|
|
|
|
|
|
// up data internally before sending it on further to the socket's queue.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This function, outgoingFlush(), is called by both the Server and Client
|
|
|
|
|
|
// to attempt to flush any pending messages out to the socket.
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.socket) return; |
|
|
|
|
|
|
|
|
|
|
|
var ret; |
|
|
var ret; |
|
|
while (this.output.length) { |
|
|
while (this.output.length) { |
|
|
|
|
|
|
|
|
if (!this.socket.writable) return; // XXX Necessary?
|
|
|
|
|
|
|
|
|
|
|
|
var data = this.output.shift(); |
|
|
var data = this.output.shift(); |
|
|
var encoding = this.outputEncodings.shift(); |
|
|
var encoding = this.outputEncodings.shift(); |
|
|
var cb = this.outputCallbacks.shift(); |
|
|
var cb = this.outputCallbacks.shift(); |
|
|
|
|
|
|
|
|
ret = this.socket.write(data, encoding, cb); |
|
|
ret = this.socket.write(data, encoding, cb); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -567,4 +561,5 @@ OutgoingMessage.prototype._flush = function() { |
|
|
// This is necessary to prevent https from breaking
|
|
|
// This is necessary to prevent https from breaking
|
|
|
this.emit('drain'); |
|
|
this.emit('drain'); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|