Browse Source

http: make OutgoingMessage._flush inline-able

v0.11.6-release
isaacs 12 years ago
parent
commit
e3157972e1
  1. 73
      lib/_http_outgoing.js

73
lib/_http_outgoing.js

@ -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;
var ret;
while (this.output.length) {
if (!this.socket.writable) return; // XXX Necessary?
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) { if (this.finished) {
// This is a queue to the server or client to bring in the next this. // This is a queue to the server or client to bring in the next this.
this._finish(); this._finish();
} else if (ret) { } else if (ret) {
// This is necessary to prevent https from breaking // This is necessary to prevent https from breaking
this.emit('drain'); this.emit('drain');
}
} }
}; };

Loading…
Cancel
Save