ConnectionPool

Struct ConnectionPool 

Source
pub struct ConnectionPool { /* private fields */ }
Expand description

Manages multiple WebSocket connections keyed by SessionId.

Thread-safe, supports concurrent access from multiple Windows. All Firefox windows connect to the same port, messages routed by session.

§Example

let pool = ConnectionPool::new().await?;
println!("WebSocket URL: {}", pool.ws_url());

// Wait for a specific session to connect
let ready_data = pool.wait_for_session(session_id).await?;

// Send a request to that session
let response = pool.send(session_id, request).await?;

Implementations§

Source§

impl ConnectionPool

Source

pub async fn new() -> Result<Arc<Self>>

Creates a new connection pool and starts the accept loop.

Binds to localhost:0 (random available port).

§Errors

Returns Error::Io if binding fails.

Source

pub async fn with_port(port: u16) -> Result<Arc<Self>>

Creates a new connection pool bound to a specific port.

§Arguments
  • port - Port to bind to (0 for random)
§Errors

Returns Error::Io if binding fails.

Source

pub async fn with_ip_port(ip: IpAddr, port: u16) -> Result<Arc<Self>>

Creates a new connection pool bound to a specific IP and port.

§Arguments
  • ip - IP address to bind to
  • port - Port to bind to (0 for random)
§Errors

Returns Error::Io if binding fails.

Source§

impl ConnectionPool

Source

pub fn ws_url(&self) -> String

Returns the WebSocket URL for this pool.

Format: ws://127.0.0.1:{port}

Source

pub fn port(&self) -> u16

Returns the port the pool is bound to.

Source

pub fn connection_count(&self) -> usize

Returns the number of active connections.

Source

pub async fn wait_for_session(&self, session_id: SessionId) -> Result<ReadyData>

Waits for a specific session to connect.

Called by spawn_window after launching Firefox. Returns when Firefox with this sessionId connects and sends READY.

§Arguments
  • session_id - The session ID to wait for
§Errors
Source

pub async fn send( &self, session_id: SessionId, request: Request, ) -> Result<Response>

Sends a request to a specific session.

§Arguments
  • session_id - Target session
  • request - Request to send
§Errors
Source

pub async fn send_with_timeout( &self, session_id: SessionId, request: Request, request_timeout: Duration, ) -> Result<Response>

Sends a request with custom timeout.

§Arguments
  • session_id - Target session
  • request - Request to send
  • timeout - Maximum time to wait for response
§Errors
Source§

impl ConnectionPool

Source

pub fn set_event_handler(&self, session_id: SessionId, handler: EventHandler)

Sets the event handler for a session.

§Arguments
  • session_id - Target session
  • handler - Event handler callback
Source

pub fn clear_event_handler(&self, session_id: SessionId)

Clears the event handler for a session.

§Arguments
  • session_id - Target session
Source§

impl ConnectionPool

Source

pub fn remove(&self, session_id: SessionId)

Removes a session from the pool.

Called when a Window closes.

§Arguments
  • session_id - Session to remove
Source

pub async fn shutdown(&self)

Shuts down the pool and all connections.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more