outbound/client_pool.js
function get_pool (port, host, local_addr, is_unix_socket, max) {
    port = port || 25;
    host = host || 'localhost';
    const name = `outbound::${port}:${host}:${local_addr}:${cfg.pool_timeout}`;
    if (!server.notes.pool) server.notes.pool = {};
    if (server.notes.pool[name]) return server.notes.pool[name];

    const pool = generic_pool.Pool({
        name,
        create: function (done) {
            _create_socket(this.name, port, host, local_addr, is_unix_socket, done);
        },
        validate: socket => socket.__fromPool && socket.writable,
        destroy: socket => {
            logger.logdebug(`[outbound] destroying pool entry ${socket.__uuid} for ${host}:${port}`);
            socket.removeAllListeners();
            socket.__fromPool = false;
            socket.on('line', line => {
                // Just assume this is a valid response
                logger.logprotocol(`[outbound] S: ${line}`);
            });
            socket.once('error', err => {
                logger.logwarn(`[outbound] Socket got an error while shutting down: ${err}`);
            });
            socket.once('end', () => {
                logger.loginfo("[outbound] Remote end half closed during destroy()");
                socket.destroy();
            })
            if (socket.writable) {
                logger.logprotocol(`[outbound] [${socket.__uuid}] C: QUIT`);
                socket.write("QUIT\r\n");
            }
            socket.end(); // half close
        },
        max: max || 10,
        idleTimeoutMillis: cfg.pool_timeout * 1000,
        log: (str, level) => {
            if (/this._availableObjects.length=/.test(str)) return;
            level = (level === 'verbose') ? 'debug' : level;
            logger[`log${level}`](`[outbound] [${name}] ${str}`);
        }
    });
    server.notes.pool[name] = pool;

    return pool;
}
function get_pool (port, host, local_addr, is_unix_socket, max) {
    port = port || 25;
    host = host || 'localhost';
    const name = `outbound::${port}:${host}:${local_addr}:${cfg.pool_timeout}`;
    if (!server.notes.pool) server.notes.pool = {};
    if (server.notes.pool[name]) return server.notes.pool[name];

    const pool = generic_pool.Pool({
        name,
        create: function (done) {
            _create_socket(this.name, port, host, local_addr, is_unix_socket, done);
        },
        validate: socket => socket.__fromPool && socket.writable,
        destroy: socket => {
            logger.logdebug(`[outbound] destroying pool entry ${socket.__uuid} for ${host}:${port}`);
            socket.removeAllListeners();
            socket.__fromPool = false;
            socket.on('line', line => {
                // Just assume this is a valid response
                logger.logprotocol(`[outbound] S: ${line}`);
            });
            socket.once('error', err => {
                logger.logwarn(`[outbound] Socket got an error while shutting down: ${err}`);
            });
            socket.once('end', () => {
                logger.loginfo("[outbound] Remote end half closed during destroy()");
                socket.destroy();
            })
            if (socket.writable) {
                logger.logprotocol(`[outbound] [${socket.__uuid}] C: QUIT`);
                socket.write("QUIT\r\n");
            }
            socket.end(); // half close
        },
        max: max || 10,
        idleTimeoutMillis: cfg.pool_timeout * 1000,
        log: (str, level) => {
            if (/this._availableObjects.length=/.test(str)) return;
            level = (level === 'verbose') ? 'debug' : level;
            logger[`log${level}`](`[outbound] [${name}] ${str}`);
        }
    });
    server.notes.pool[name] = pool;

    return pool;
}
function get_pool ( port , host , local_addr , is_unix_socket , max ) { port = port || 25 ; host = host || 'localhost' ; const name = ` ${ port } ${ host } ${ local_addr } ${ cfg . pool_timeout } ` ; if ( ! server . notes . pool ) server . notes . pool = { } ; if ( server . notes . pool [ name ] ) return server . notes . pool [ name ] ; const pool = generic_pool . Pool ( { name , create : function ( done ) { _create_socket ( this . name , port , host , local_addr , is_unix_socket , done ) ; } , validate : socket => socket . __fromPool && socket . writable , destroy : socket => { logger . logdebug ( ` ${ socket . __uuid } ${ host } ${ port } ` ) ; socket . removeAllListeners ( ) ; socket . __fromPool = false ; socket . on ( 'line' , line => { // Just assume this is a valid response logger . logprotocol ( ` ${ line } ` ) ; } ) ; socket . once ( 'error' , err => { logger . logwarn ( ` ${ err } ` ) ; } ) ; socket . once ( 'end' , ( ) => { logger . loginfo ( "[outbound] Remote end half closed during destroy()" ) ; socket . destroy ( ) ; } ) if ( socket . writable ) { logger . logprotocol ( ` ${ socket . __uuid } ` ) ; socket . write ( "QUIT\r\n" ) ; } socket . end ( ) ; // half close } , max : max || 10 , idleTimeoutMillis : cfg . pool_timeout * 1000 , log : ( str , level ) => { if ( / this._availableObjects.length= / . test ( str ) ) return ; level = ( level === 'verbose' ) ? 'debug' : level ; logger [ ` ${ level } ` ] ( ` ${ name } ${ str } ` ) ; } } ) ; server . notes . pool [ name ] = pool ; return pool ; }
Separate pools are kept for each set of server attributes.
Separate pools are kept for each set of server attributes .