Rust

memory

Module

An in-process adapter: connections, messages and requests are driven by calls, and what the server sends is recorded.

Contents

use utopia_websocket::memory::Closed;
Rust
pub struct Closed

A connection the server closed.

use utopia_websocket::memory::Frame;
Rust
pub struct Frame

A message the server sent to one connection.

use utopia_websocket::Memory;
Rust
pub struct Memory
  • start calls the start hook, then the worker start hook for each worker (0 to the worker number, one by default); shutdown calls the worker stop hook for each worker of a started server.
  • send records a Frame for each open connection in the list and skips the others.
  • close closes an open connection, records it and calls the close hook, as Swoole does.
  • fail makes one stage fail, to exercise Server::error.

Clones share the same server.

Rust
use utopia_websocket::{Memory, Server};

let adapter = Memory::new();
let server = Server::new(adapter.clone());
server.on_open(|connection, _| println!("connected {connection}"));

adapter.open(7, &Default::default());
server.send(&[7, 8], "hello");

assert_eq!(adapter.frames().len(), 1); // 8 is not open
assert_eq!(adapter.connections(), [7]);
use utopia_websocket::memory::Settings;
Rust
pub struct Settings

What the configuration setters were given; None for a setter not called.