Struct Server

Source
pub struct Server<P: Default + Send + Sync> { /* private fields */ }
Expand description

Represents a TODO server which manages all TCP connections.

Implementations§

Source§

impl<P: 'static + Default + Send + Sync + Clone> Server<P>

Source

pub fn install(platform: &Arc<Platform>) -> Arc<Self>

Creates and installs a Server into the given Platform.

Note that this is called by the Builder unless disabled.

Also note, that this will not technically start the server. This has to be done manually via event_loop as it is most probable done in the main thread.

Source

pub fn connections(&self) -> Vec<ConnectionInfo<P>>

Lists all currently active connections.

Source

pub fn kill(&self, peer_address: &str) -> bool

Kills the connection of the given peer address.

Source

pub fn fork<F>( server: &Arc<Server<P>>, client_loop: &'static (impl Fn(Arc<Platform>, Arc<Connection<P>>, TcpStream) -> F + Send + Sync), )
where F: Future<Output = Result<()>> + Send + Sync,

Starts the event loop in a separate thread.

This is most probably used by test scenarios where the tests itself run in the main thread.

Source

pub async fn fork_and_await<F>( server: &Arc<Server<P>>, client_loop: &'static (impl Fn(Arc<Platform>, Arc<Connection<P>>, TcpStream) -> F + Send + Sync), )
where F: Future<Output = Result<()>> + Send + Sync,

Starts the event loop in a separate thread and waits until the server is up and running.

Just like fork this is intended to be used in test environments.

Source

pub async fn event_loop<F>( &self, client_loop: impl Fn(Arc<Platform>, Arc<Connection<P>>, TcpStream) -> F + Send + Sync + Copy + 'static, )
where F: Future<Output = Result<()>> + Send,

Tries to open a server socket on the specified address to serve incoming client connections.

The task of this loop is to bind the server socket to the specified address. Once this was successful, we enter the server_loop to actually handle incoming connections. Once this loop returns, either the platform is no longer running and we should exit, or the config has changed and we should try to bind the server to the new address.

Auto Trait Implementations§

§

impl<P> !Freeze for Server<P>

§

impl<P> RefUnwindSafe for Server<P>

§

impl<P> Send for Server<P>

§

impl<P> Sync for Server<P>

§

impl<P> Unpin for Server<P>

§

impl<P> UnwindSafe for Server<P>

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 = 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.