From 6176e49181fcf81eb22919e2880b503d3f70e738 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 15 May 2013 14:24:08 -0700 Subject: [PATCH] http: style --- lib/_http_agent.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 7ad5c7ec56a..c6983b779a1 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -66,6 +66,7 @@ function Agent(options) { }); self.createConnection = net.createConnection; } + util.inherits(Agent, EventEmitter); exports.Agent = Agent; @@ -91,6 +92,7 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) { this.requests[name].push(req); } }; + Agent.prototype.createSocket = function(name, host, port, localAddress, req) { var self = this; var options = util._extend({}, self.options); @@ -111,18 +113,21 @@ Agent.prototype.createSocket = function(name, host, port, localAddress, req) { self.sockets[name] = []; } this.sockets[name].push(s); - var onFree = function() { + + function onFree() { self.emit('free', s, host, port, localAddress); } s.on('free', onFree); - var onClose = function(err) { + + function onClose(err) { // This is the only place where sockets get removed from the Agent. // If you want to remove a socket from the pool, just close it. // All socket errors end in a close event anyway. self.removeSocket(s, name, host, port, localAddress); } s.on('close', onClose); - var onRemove = function() { + + function onRemove() { // We need this function for cases like HTTP 'upgrade' // (defined by WebSockets) where we need to remove a socket from the pool // because it'll be locked up indefinitely @@ -134,6 +139,7 @@ Agent.prototype.createSocket = function(name, host, port, localAddress, req) { s.on('agentRemove', onRemove); return s; }; + Agent.prototype.removeSocket = function(s, name, host, port, localAddress) { if (this.sockets[name]) { var index = this.sockets[name].indexOf(s);