http: make OutgoingMessage._flush inline-able
This commit is contained in:
parent
da93d6adfb
commit
e3157972e1
@ -525,46 +525,41 @@ 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) {
|
||||||
//
|
var ret;
|
||||||
// In both HTTP servers and clients it is possible to queue up several
|
while (this.output.length) {
|
||||||
// outgoing messages. This is easiest to imagine in the case of a client.
|
var data = this.output.shift();
|
||||||
// Take the following situation:
|
var encoding = this.outputEncodings.shift();
|
||||||
//
|
var cb = this.outputCallbacks.shift();
|
||||||
// req1 = client.request('GET', '/');
|
ret = this.socket.write(data, encoding, cb);
|
||||||
// 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;
|
if (this.finished) {
|
||||||
|
// This is a queue to the server or client to bring in the next this.
|
||||||
var ret;
|
this._finish();
|
||||||
while (this.output.length) {
|
} else if (ret) {
|
||||||
|
// This is necessary to prevent https from breaking
|
||||||
if (!this.socket.writable) return; // XXX Necessary?
|
this.emit('drain');
|
||||||
|
}
|
||||||
var data = this.output.shift();
|
|
||||||
var encoding = this.outputEncodings.shift();
|
|
||||||
var cb = this.outputCallbacks.shift();
|
|
||||||
|
|
||||||
ret = this.socket.write(data, encoding, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.finished) {
|
|
||||||
// This is a queue to the server or client to bring in the next this.
|
|
||||||
this._finish();
|
|
||||||
} else if (ret) {
|
|
||||||
// This is necessary to prevent https from breaking
|
|
||||||
this.emit('drain');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user