import * as plugins from '../../plugins.js';
import type { SmartProxy } from './smart-proxy.js';
/**
 * PortManager handles the dynamic creation and removal of port listeners
 *
 * This class provides methods to add and remove listening ports at runtime,
 * allowing SmartProxy to adapt to configuration changes without requiring
 * a full restart.
 *
 * It includes a reference counting system to track how many routes are using
 * each port, so ports can be automatically released when they are no longer needed.
 */
export declare class PortManager {
    private smartProxy;
    private servers;
    private isShuttingDown;
    private portRefCounts;
    /**
     * Create a new PortManager
     *
     * @param smartProxy The SmartProxy instance
     */
    constructor(smartProxy: SmartProxy);
    /**
     * Start listening on a specific port
     *
     * @param port The port number to listen on
     * @returns Promise that resolves when the server is listening or rejects on error
     */
    addPort(port: number): Promise<void>;
    /**
     * Stop listening on a specific port
     *
     * @param port The port to stop listening on
     * @returns Promise that resolves when the server is closed
     */
    removePort(port: number): Promise<void>;
    /**
     * Add multiple ports at once
     *
     * @param ports Array of ports to add
     * @returns Promise that resolves when all servers are listening
     */
    addPorts(ports: number[]): Promise<void>;
    /**
     * Remove multiple ports at once
     *
     * @param ports Array of ports to remove
     * @returns Promise that resolves when all servers are closed
     */
    removePorts(ports: number[]): Promise<void>;
    /**
     * Update listening ports to match the provided list
     *
     * This will add any ports that aren't currently listening,
     * and remove any ports that are no longer needed.
     *
     * @param ports Array of ports that should be listening
     * @returns Promise that resolves when all operations are complete
     */
    updatePorts(ports: number[]): Promise<void>;
    /**
     * Get all ports that are currently listening
     *
     * @returns Array of port numbers
     */
    getListeningPorts(): number[];
    /**
     * Mark the port manager as shutting down
     */
    setShuttingDown(isShuttingDown: boolean): void;
    /**
     * Close all listening servers
     *
     * @returns Promise that resolves when all servers are closed
     */
    closeAll(): Promise<void>;
    /**
     * Get all server instances (for testing or debugging)
     */
    getServers(): Map<number, plugins.net.Server>;
    /**
     * Check if a port is bound by this SmartProxy instance
     *
     * @param port The port number to check
     * @returns True if the port is currently bound by SmartProxy
     */
    isPortBoundBySmartProxy(port: number): boolean;
    /**
     * Get the current reference count for a port
     *
     * @param port The port number to check
     * @returns The number of routes using this port, 0 if none
     */
    getPortRefCount(port: number): number;
    /**
     * Increment the reference count for a port
     *
     * @param port The port number to increment
     * @returns The new reference count
     */
    incrementPortRefCount(port: number): number;
    /**
     * Decrement the reference count for a port
     *
     * @param port The port number to decrement
     * @returns The new reference count
     */
    decrementPortRefCount(port: number): number;
    /**
     * Determine if a port binding error is due to an external or internal conflict
     *
     * @param error The error object from a failed port binding
     * @returns Object indicating if this is a conflict and if it's external
     */
    private isPortConflict;
}
