Skip to main content

Server

Struct Server 

Source
pub struct Server<T: XvcServer> { /* private fields */ }

Implementations§

Source§

impl<T: XvcServer> Server<T>

Source

pub fn new(server: T, config: Config) -> Server<T>

Create a new server wrapping server with the given config.

Examples found in repository?
examples/mock_server.rs (line 43)
42async fn main() -> Result<(), Box<dyn std::error::Error>> {
43    let server = Server::new(Loopback, Config::default());
44    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 2542);
45    println!("XVC loopback server listening on {addr}");
46    server.listen(addr).await?;
47    Ok(())
48}
Source

pub async fn listen(&self, addr: impl ToSocketAddrs) -> Result<()>
where T: Send + 'static,

Bind to addr and serve clients until the process exits.

This is the standard production entry point. To shut the server down programmatically (e.g. in tests), use listen_on with a CancellationToken.

Examples found in repository?
examples/mock_server.rs (line 46)
42async fn main() -> Result<(), Box<dyn std::error::Error>> {
43    let server = Server::new(Loopback, Config::default());
44    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 2542);
45    println!("XVC loopback server listening on {addr}");
46    server.listen(addr).await?;
47    Ok(())
48}
Source

pub async fn listen_on( &self, listener: TcpListener, shutdown: CancellationToken, ) -> Result<()>
where T: Send + 'static,

Serve clients from a pre-bound listener until shutdown is cancelled.

When shutdown is cancelled the accept loop exits cleanly; any connection that is already being served runs to completion before the task finishes.

This entry point is useful when the caller needs to control the server lifetime programmatically — for example in tests, or to hook into a process-wide signal handler:

let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
let addr = listener.local_addr()?;
let token = CancellationToken::new();

// Shut down on Ctrl+C
tokio::spawn({
    let token = token.clone();
    async move {
        tokio::signal::ctrl_c().await.unwrap();
        token.cancel();
    }
});

server.listen_on(listener, token).await?;

Trait Implementations§

Source§

impl<T: Debug + XvcServer> Debug for Server<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Server<T>

§

impl<T> !UnwindSafe for Server<T>

§

impl<T> Freeze for Server<T>
where Arc<Mutex<T>>: Freeze,

§

impl<T> Send for Server<T>
where Arc<Mutex<T>>: Send,

§

impl<T> Sync for Server<T>
where Arc<Mutex<T>>: Sync,

§

impl<T> Unpin for Server<T>
where Arc<Mutex<T>>: Unpin,

§

impl<T> UnsafeUnpin for Server<T>
where Arc<Mutex<T>>: UnsafeUnpin,

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.