|
@ -1067,7 +1067,7 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) { |
|
|
} |
|
|
} |
|
|
if (this.sockets[name].length < this.maxSockets) { |
|
|
if (this.sockets[name].length < this.maxSockets) { |
|
|
// If we are under maxSockets create a new one.
|
|
|
// If we are under maxSockets create a new one.
|
|
|
req.onSocket(this.createSocket(name, host, port, localAddress, req)); |
|
|
req.onSocket(this.createSocket(name, host, port, localAddress)); |
|
|
} else { |
|
|
} else { |
|
|
// We are over limit so we'll add it to the queue.
|
|
|
// We are over limit so we'll add it to the queue.
|
|
|
if (!this.requests[name]) { |
|
|
if (!this.requests[name]) { |
|
@ -1076,13 +1076,13 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) { |
|
|
this.requests[name].push(req); |
|
|
this.requests[name].push(req); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
Agent.prototype.createSocket = function(name, host, port, localAddress, req) { |
|
|
Agent.prototype.createSocket = function(name, host, port, localAddress) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var options = util._extend({}, self.options); |
|
|
var options = util._extend({}, self.options); |
|
|
options.port = port; |
|
|
options.port = port; |
|
|
options.host = host; |
|
|
options.host = host; |
|
|
options.localAddress = localAddress; |
|
|
options.localAddress = localAddress; |
|
|
var s = self.createConnection.call(req, options); |
|
|
var s = self.createConnection(options); |
|
|
if (!self.sockets[name]) { |
|
|
if (!self.sockets[name]) { |
|
|
self.sockets[name] = []; |
|
|
self.sockets[name] = []; |
|
|
} |
|
|
} |
|
@ -1123,11 +1123,7 @@ Agent.prototype.removeSocket = function(s, name, host, port, localAddress) { |
|
|
} |
|
|
} |
|
|
if (this.requests[name] && this.requests[name].length) { |
|
|
if (this.requests[name] && this.requests[name].length) { |
|
|
// If we have pending requests and a socket gets closed a new one
|
|
|
// If we have pending requests and a socket gets closed a new one
|
|
|
this.createSocket(name, |
|
|
this.createSocket(name, host, port, localAddress).emit('free'); |
|
|
host, |
|
|
|
|
|
port, |
|
|
|
|
|
localAddress, |
|
|
|
|
|
this.requests[name][0]).emit('free'); |
|
|
|
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -1139,7 +1135,6 @@ function ClientRequest(options, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
OutgoingMessage.call(self); |
|
|
OutgoingMessage.call(self); |
|
|
|
|
|
|
|
|
this.options = util._extend({}, options); |
|
|
|
|
|
self.agent = options.agent === undefined ? globalAgent : options.agent; |
|
|
self.agent = options.agent === undefined ? globalAgent : options.agent; |
|
|
|
|
|
|
|
|
var defaultPort = options.defaultPort || 80; |
|
|
var defaultPort = options.defaultPort || 80; |
|
@ -1199,7 +1194,7 @@ function ClientRequest(options, cb) { |
|
|
self._last = true; |
|
|
self._last = true; |
|
|
self.shouldKeepAlive = false; |
|
|
self.shouldKeepAlive = false; |
|
|
if (options.createConnection) { |
|
|
if (options.createConnection) { |
|
|
self.onSocket(options.createConnection.call(self, self.socketPath)); |
|
|
self.onSocket(options.createConnection(self.socketPath)); |
|
|
} else { |
|
|
} else { |
|
|
self.onSocket(net.createConnection(self.socketPath)); |
|
|
self.onSocket(net.createConnection(self.socketPath)); |
|
|
} |
|
|
} |
|
@ -1215,7 +1210,7 @@ function ClientRequest(options, cb) { |
|
|
if (options.createConnection) { |
|
|
if (options.createConnection) { |
|
|
options.port = port; |
|
|
options.port = port; |
|
|
options.host = host; |
|
|
options.host = host; |
|
|
var conn = options.createConnection.call(self, options); |
|
|
var conn = options.createConnection(options); |
|
|
} else { |
|
|
} else { |
|
|
var conn = net.createConnection({ |
|
|
var conn = net.createConnection({ |
|
|
port: port, |
|
|
port: port, |
|
|