Lines Matching defs:this

4 // copy of this software and associated documentation files (the
11 // The above copyright notice and this permission notice shall be included
68 // Surprisingly, this is still API compatible as far as third parties are
78 this.type = type;
79 this.handle = handle;
84 const socket = this;
91 if (!(this instanceof Agent))
94 FunctionPrototypeCall(EventEmitter, this);
96 this.defaultPort = 80;
97 this.protocol = 'http:';
99 this.options = { __proto__: null, ...options };
101 if (this.options.noDelay === undefined)
102 this.options.noDelay = true;
105 this.options.path = null;
106 this.requests = ObjectCreate(null);
107 this.sockets = ObjectCreate(null);
108 this.freeSockets = ObjectCreate(null);
109 this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
110 this.keepAlive = this.options.keepAlive || false;
111 this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
112 this.maxFreeSockets = this.options.maxFreeSockets || 256;
113 this.scheduling = this.options.scheduling || 'lifo';
114 this.maxTotalSockets = this.options.maxTotalSockets;
115 this.totalSocketCount = 0;
117 validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);
119 if (this.maxTotalSockets !== undefined) {
120 validateNumber(this.maxTotalSockets, 'maxTotalSockets', 1);
122 this.maxTotalSockets = Infinity;
125 this.on('free', (socket, options) => {
126 const name = this.getName(options);
131 // case of socket.destroy() below this 'error' has no handler
139 const requests = this.requests[name];
147 setRequestSocket(this, req, socket);
151 setRequestSocket(this, req, socket);
154 delete this.requests[name];
162 if (!req || !req.shouldKeepAlive || !this.keepAlive) {
167 const freeSockets = this.freeSockets[name] || [];
170 if (this.sockets[name])
171 count += this.sockets[name].length;
173 if (this.totalSocketCount > this.maxTotalSockets ||
174 count > this.maxSockets ||
175 freeLen >= this.maxFreeSockets ||
176 !this.keepSocketAlive(socket)) {
181 this.freeSockets[name] = freeSockets;
184 this.removeSocket(socket, options);
191 this.on('newListener', maybeEnableKeylog);
198 this.removeListener('newListener', maybeEnableKeylog);
200 const agent = this;
201 this[kOnKeylog] = function onkeylog(keylog) {
202 agent.emit('keylog', keylog, this);
205 const sockets = ObjectValues(this.sockets);
207 sockets[i].on('keylog', this[kOnKeylog]);
251 options = { __proto__: null, ...options, ...this.options };
258 const name = this.getName(options);
259 if (!this.sockets[name]) {
260 this.sockets[name] = [];
263 const freeSockets = this.freeSockets[name];
269 socket = this.scheduling === 'fifo' ?
273 delete this.freeSockets[name];
277 const sockLen = freeLen + this.sockets[name].length;
281 this.reuseSocket(socket, req);
282 setRequestSocket(this, req, socket);
283 ArrayPrototypePush(this.sockets[name], socket);
284 } else if (sockLen < this.maxSockets &&
285 this.totalSocketCount < this.maxTotalSockets) {
288 this.createSocket(req, options, (err, socket) => {
292 setRequestSocket(this, req, socket);
297 if (!this.requests[name]) {
298 this.requests[name] = [];
306 ArrayPrototypePush(this.requests[name], req);
311 options = { __proto__: null, ...options, ...this.options };
318 const name = this.getName(options);
327 if (!this.sockets[name]) {
328 this.sockets[name] = [];
330 ArrayPrototypePush(this.sockets[name], s);
331 this.totalSocketCount++;
332 debug('sockets', name, this.sockets[name].length, this.totalSocketCount);
333 installListeners(this, s, options);
337 if (this.keepAlive) {
338 options.keepAlive = this.keepAlive;
339 options.keepAliveInitialDelay = this.keepAliveMsecs;
341 const newSocket = this.createConnection(options, oncreate);
406 // We need this function for cases like HTTP 'upgrade'
425 const name = this.getName(options);
427 const sets = [this.sockets];
431 ArrayPrototypePush(sets, this.freeSockets);
448 if (this.requests[name] && this.requests[name].length) {
450 req = this.requests[name][0];
452 // TODO(rickyes): this logic will not be FIFO across origins.
456 const keys = ObjectKeys(this.requests);
459 // Check whether this specific origin is already at maxSockets
460 if (this.sockets[prop] && this.sockets[prop].length) break;
463 req = this.requests[prop][0];
472 this.createSocket(req, options, (err, socket) => {
483 socket.setKeepAlive(true, this.keepAliveMsecs);
486 const agentTimeout = this.options.timeout || 0;
502 const sets = [this.freeSockets, this.sockets];