import * as plugins from '../../plugins.js';
export interface CleanupOptions {
    immediate?: boolean;
    allowDrain?: boolean;
    gracePeriod?: number;
}
export interface SafeSocketOptions {
    port: number;
    host: string;
    onError?: (error: Error) => void;
    onConnect?: () => void;
    timeout?: number;
}
/**
 * Safely cleanup a socket by removing all listeners and destroying it
 * @param socket The socket to cleanup
 * @param socketName Optional name for logging
 * @param options Cleanup options
 */
export declare function cleanupSocket(socket: plugins.net.Socket | plugins.tls.TLSSocket | null, socketName?: string, options?: CleanupOptions): Promise<void>;
/**
 * Create independent cleanup handlers for paired sockets that support half-open connections
 * @param clientSocket The client socket
 * @param serverSocket The server socket
 * @param onBothClosed Callback when both sockets are closed
 * @returns Independent cleanup functions for each socket
 */
export declare function createIndependentSocketHandlers(clientSocket: plugins.net.Socket | plugins.tls.TLSSocket, serverSocket: plugins.net.Socket | plugins.tls.TLSSocket, onBothClosed: (reason: string) => void, options?: {
    enableHalfOpen?: boolean;
}): {
    cleanupClient: (reason: string) => Promise<void>;
    cleanupServer: (reason: string) => Promise<void>;
};
/**
 * Setup socket error and close handlers with proper cleanup
 * @param socket The socket to setup handlers for
 * @param handleClose The cleanup function to call
 * @param handleTimeout Optional custom timeout handler
 * @param errorPrefix Optional prefix for error messages
 */
export declare function setupSocketHandlers(socket: plugins.net.Socket | plugins.tls.TLSSocket, handleClose: (reason: string) => void, handleTimeout?: (socket: plugins.net.Socket | plugins.tls.TLSSocket) => void, errorPrefix?: string): void;
/**
 * Setup bidirectional data forwarding between two sockets with proper cleanup
 * @param clientSocket The client/incoming socket
 * @param serverSocket The server/outgoing socket
 * @param handlers Object containing optional handlers for data and cleanup
 * @returns Cleanup functions for both sockets
 */
export declare function setupBidirectionalForwarding(clientSocket: plugins.net.Socket | plugins.tls.TLSSocket, serverSocket: plugins.net.Socket | plugins.tls.TLSSocket, handlers: {
    onClientData?: (chunk: Buffer) => void;
    onServerData?: (chunk: Buffer) => void;
    onCleanup: (reason: string) => void;
    enableHalfOpen?: boolean;
}): {
    cleanupClient: (reason: string) => Promise<void>;
    cleanupServer: (reason: string) => Promise<void>;
};
/**
 * Create a socket with immediate error handling to prevent crashes
 * @param options Socket creation options
 * @returns The created socket
 */
export declare function createSocketWithErrorHandler(options: SafeSocketOptions): plugins.net.Socket;
