How to use the forever-agent.SSL.defaultMinSockets function in forever-agent

To help you get started, we’ve selected a few forever-agent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github itteco / iframely / lib / agent.js View on Github external
Agent.prototype.init = function init(url, options) {
    var self = this;

    self.state = {};
    self.options = options || {};

    self.options.host = url.host;
    self.options.protocol = url.protocol;
    self.options.port = url.protocol === 'http:' ? 80 : 443;

    self.requests = {};
    self.sockets = {};
    self.freeSockets = {};
    self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets;
    self.minSockets = self.options.minSockets || HttpsAgent.defaultMinSockets;
    self.on('free', function(socket, host, port) {
        var name = getConnectionName(host, port);

        if (self.requests[name] && self.requests[name].length) {
            self.requests[name].shift().onSocket(socket)
        } else if (self.sockets[name].length < self.minSockets) {
            if (!self.freeSockets[name]) self.freeSockets[name] = [];
            self.freeSockets[name].push(socket);

            // if an error happens while we don't use the socket anyway, meh, throw the socket away
            var onIdleError = function() {
                socket.destroy();
            };
            socket._onIdleError = onIdleError;
            //socket.on('error', onIdleError);
        } else {

forever-agent

HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.

Apache-2.0
Latest version published 10 years ago

Package Health Score

74 / 100
Full package analysis

Similar packages