RUMServer

Struct RUMServer 

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

This is the Server primitive that listens for incoming connections and manages “low-level” messages.

This struct tracks accepting new clients via RUMServer::handle_accept, incoming messages via RUMServer::handle_receive and message dispatchs via RUMServer::handle_send.

All key methods are async and shall be run exclusively in the async context. We provide a set of tools that allow you to interact with this struct from sync code. One such tool is RUMServerHandle.

The RUMServer::run method orchestrate a series of steps that allows starting server management. The result is that the server will check for connections and messages autonomously. You want to call this method in a non blocking manner from the sync context, so that the server can handle the transactions in the background

Implementations§

Source§

impl RUMServer

Source

pub async fn new(ip: &str, port: u16) -> RUMResult<RUMServer>

Constructs a server and binds the port on interface denoted by ip. The server management is not started until you invoke RUMServer::run.

Source

pub async fn run(ctx: SafeServer) -> RUMResult<()>

Main, juicy server management logic. Call this method to kick start a series of autonomous checks. Message handling and connection handling are taken care autonamtically.

Await this method if you wish to block the context thread indefinitely. This method has a never ending loop looking for when the server has been signalled to shut down.

ctx here refers to an instance of the server wrapped by SafeServer. This was done to be able to make the management logic work autonomously across threads. We call the RWLock’s read() method every pass of the loop and await on it. This allows the runtime to progress the state of other futures and allow sync code to interact with the server state. In most situations, this step should yield a no-op.

Source

pub async fn stop_server(ctx: &SafeServer) -> RUMResult<RUMString>

This method signals the server to stop.

Then, this method waits for run to cleanup before exiting. Meaning, this method’s exit is enough to signal everything went through smoothly.

Source

pub async fn handle_accept( listener: SafeListener, clients: Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, tx_in: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, tx_out: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, ) -> RUMResult<()>

Contains basic logic for listening for incoming connections.

Source

pub async fn handle_send( clients: Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, tx_out: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, ) -> RUMResult<()>

Contains logic for sending messages queued for a client to it. tx_out is a reference of [SafeMappedQueues] which is a hash map of [SafeQueue] whose keys are the client’s peer address string.

Source

pub async fn handle_receive( clients: Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, tx_in: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, ) -> RUMResult<()>

Contains the logic for handling receiving messages from clients. Incoming messages are all placed into a queue that the “outside” world can interact with.

Source

pub async fn handle_client_gc( clients: Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, tx_in: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, tx_out: Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, ) -> RUMResult<()>

Contains the logic for handling removal of clients from the server if they disconnected.

Source

pub async fn register_queue( tx_queues: &Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, client: &RUMString, )

Source

pub async fn push_queue( tx_queues: &Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, client: &RUMString, msg: RUMNetMessage, ) -> RUMResult<()>

Source

pub async fn pop_queue( tx_queues: &Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, client: &RUMString, ) -> Option<Vec<RUMNetMessage>>

Source

pub async fn is_queue_empty( tx_queues: &Arc<AsyncMutex<HashMap<RUMString, Arc<AsyncMutex<VecDeque<RUMNetMessage>>>>>>, client: &RUMString, ) -> bool

Source

pub async fn send(client: &SafeClient, msg: &RUMNetMessage) -> RUMResult<()>

Source

pub async fn receive(client: &SafeClient) -> RUMResult<RUMNetMessage>

Source

pub async fn disconnect(client: &SafeClient)

Source

pub async fn get_client( clients: &Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, client: &RUMString, ) -> RUMResult<SafeClient>

Source

pub async fn get_client_ids( clients: &Arc<AsyncRwLock<HashMap<RUMString, SafeClient>>>, ) -> ClientIDList

Return client id list.

Source

pub async fn get_client_id(client: &SafeClient) -> RUMString

Source

pub async fn get_client_readiness( client: &SafeClient, socket_readiness_type: &SOCKET_READINESS_TYPE, ) -> bool

Source

pub async fn get_clients(&self) -> ClientList

Return list of clients.

Source

pub async fn push_message( &mut self, client_id: &RUMString, msg: RUMNetMessage, ) -> RUMResult<()>

Queues a message onto the server to send to client.

Source

pub async fn pop_message( &mut self, client_id: &RUMString, ) -> Option<RUMNetMessage>

Obtain a message, if available, from the incoming queue.

Source

pub async fn wait_incoming(&mut self, client_id: &RUMString) -> RUMResult<bool>

Obtain a message, if available, from the incoming queue.

Source

pub async fn get_address_info(&self) -> Option<RUMString>

Get the Address:Port info for this socket.

Source

pub async fn gc_clients(&mut self) -> RUMResult<()>

Attempts to clear clients that have been marked as disconnected.

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