A class for handling ordered data writes to a proxy socket. This class manages write queues for multiple connections and ensures data is sent in the correct order.

  • Maintains separate write queues for each connection name.
  • Handles backpressure and ensures reliable delivery of data chunks.
  • Supports asynchronous writes with proper error handling.
  • Create an instance by providing a proxy socket and its associated subdomain.
  • Use writeDataInOrder to enqueue data for a specific connection name.
  • The class will automatically manage the processing of the queue for each connection.

Constructors

  • Initializes a new instance of the ProxySocketHandler class.

    Parameters

    • proxySocket: Socket

      The proxy socket used for communication.

    • subdomain: string

      The subdomain associated with the connection.

    Returns ProxySocketHandler

Methods

  • Processes the write queue for a specific connection name. Writes data in chunks to the proxy socket while ensuring the order of operations is maintained.

    Parameters

    • name: string

      The name of the connection whose queue is being processed.

    Returns Promise<void>

    A promise that resolves when the queue is fully processed.

    • Extracts and writes data in 1024-byte chunks.
    • Creates a structured message containing metadata and the data chunk.
    • Writes the message to the proxy socket and waits for the write callback.
    • Resolves or rejects the original promises based on the success or failure of the operation.
  • Adds data to the write queue for a specific connection name and ensures it is written in order. If the queue is not already being processed, it starts processing immediately.

    Parameters

    • buffer: Buffer

      The data to be written to the proxy socket.

    • name: string

      The name of the connection associated with the data.

    Returns Promise<void>

    A promise that resolves when the data is successfully written or rejects if an error occurs.

    • Adds the provided buffer to the write queue for the given connection name.
    • Starts processing the queue if not already processing.