pub struct SocketServer<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> { /* private fields */ }
Expand description

The handle to define, start and shutdown a Reactive Server for Socket Connections.
BUFFERED_MESSAGES_PER_PEER_COUNT is the number of messages that may be produced ahead of sending (to each client) as well as the number of messages that this server may accumulate from each client before denying new ones

Implementations§

source§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

source

pub fn new<IntoString: Into<String>>( interface_ip: IntoString, port: u16 ) -> Self

Creates a new server instance listening on TCP/IP: interface_ip: the interface’s IP to listen to – 0.0.0.0 will cause listening to all network interfaces port: what port to listen to processor_builder_fn: a function to instantiate a new processor Stream whenever a new connection arrives

source

pub async fn spawn_responsive_processor<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + ResponsiveMessages<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, ServerStreamType: Stream<Item = ServerMessages> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<BUFFERED_MESSAGES_PER_PEER_COUNT, ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<BUFFERED_MESSAGES_PER_PEER_COUNT, ServerMessages>>, ProcessorRemoteStreamType<BUFFERED_MESSAGES_PER_PEER_COUNT, ClientMessages>) -> ServerStreamType + Send + Sync + 'static>( &mut self, connection_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn ) -> Result<(), Box<dyn Error + Sync + Send + 'static>>

Spawns a task to run a Server listening @ self’s interface_ip & port and returns, immediately, an object through which the caller may inquire some stats (if opted in) and request the server to shutdown.
The given dialog_processor_builder_fn will be called for each new client and will return a reactive-mutiny Stream that will produce non-futures & non-fallibles ServerMessages that will be sent to the clients.

source

pub async fn spawn_unresponsive_processor<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, OutputStreamItemsType: Send + Sync + Debug + 'static, ServerStreamType: Stream<Item = OutputStreamItemsType> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<BUFFERED_MESSAGES_PER_PEER_COUNT, ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<BUFFERED_MESSAGES_PER_PEER_COUNT, ServerMessages>>, ProcessorRemoteStreamType<BUFFERED_MESSAGES_PER_PEER_COUNT, ClientMessages>) -> ServerStreamType + Send + Sync + 'static>( &mut self, connection_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn ) -> Result<(), Box<dyn Error + Sync + Send + 'static>>

Spawns a task to run a Server listening @ self’s interface_ip & port and returns, immediately, an object through which the caller may inquire some stats (if opted in) and request the server to shutdown.
The given dialog_processor_builder_fn will be called for each new client and will return a reactive-mutiny Stream that will produce non-futures & non-fallibles items that won’t be sent to the clients – if you want the processor to produce “answer messages” to the clients, see SocketServer::spawn_responsive_processor().

source

pub fn shutdown_waiter( &mut self ) -> impl FnOnce() -> BoxFuture<'static, Result<(), Box<dyn Error + Send + Sync>>>

Returns an async closure that blocks until [shutdown()] is called. Example:

    self.shutdown_waiter()().await;
source

pub fn shutdown(self, timeout_ms: u32) -> Result<(), Box<dyn Error>>

Notifies the server it is time to shutdown.
The provided connection_events callback will be executed for up to timeout_ms milliseconds – in which case it is a good practice to inform all the clients that a server-initiated disconnection (due to a shutdown) is happening.

Trait Implementations§

source§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> Debug for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> !RefUnwindSafe for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> Send for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> Sync for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> Unpin for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

§

impl<const BUFFERED_MESSAGES_PER_PEER_COUNT: usize> !UnwindSafe for SocketServer<BUFFERED_MESSAGES_PER_PEER_COUNT>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.