Struct CompositeSocketServer

Source
pub struct CompositeSocketServer<const CONFIG: u64, StateType: Send + Sync + Clone + Debug + 'static> { /* private fields */ }
Expand description

Real definition & implementation for our Socket Server, full of generic parameters.
Probably you want to instantiate this structure through the sugared macros new_socket_server!() or new_composite_socket_server!() instead. Generic Parameters:

  • CONFIG: the u64 version of the [ConstConfig] instance used to build this struct – from which ProcessorUniType and SenderChannel derive;
  • RemoteMessages: the messages that are generated by the clients (usually an enum);
  • LocalMessages: the messages that are generated by the server (usually an enum);
  • ProcessorUniType: an instance of a reactive-mutiny’s [Uni] type (using one of the zero-copy channels) – This [Uni] will execute the given server reactive logic for each incoming message (see how it is used in new_socket_server!() or new_composite_socket_server!());
  • SenderChannel: an instance of a reactive-mutiny’s Uni movable Channel, which will provide a Stream of messages to be sent to the client;
  • StateType: The state type used by the “connection routing closure” (to be provided), enabling the “Composite Protocol Stacking” pattern.

Implementations§

Source§

impl<const CONFIG: u64, StateType: Send + Sync + Clone + Debug + 'static> CompositeSocketServer<CONFIG, StateType>

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

Trait Implementations§

Source§

impl<const CONFIG: u64, StateType: Send + Sync + Clone + Debug + 'static> MessagingService<CONFIG> for CompositeSocketServer<CONFIG, StateType>

Source§

type StateType = StateType

Source§

async fn spawn_processor<RemoteMessages: ReactiveMessagingDeserializer<RemoteMessages> + Send + Sync + PartialEq + Debug + 'static, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug + 'static, ProcessorUniType: GenericUni<ItemType = RemoteMessages> + Send + Sync + 'static, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync + 'static, OutputStreamItemsType: Send + Sync + Debug + 'static, ServerStreamType: Stream<Item = OutputStreamItemsType> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send + 'static, ConnectionEventsCallback: Fn(ProtocolEvent<CONFIG, LocalMessages, SenderChannel, StateType>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<CONFIG, LocalMessages, SenderChannel, StateType>>, MessagingMutinyStream<ProcessorUniType>) -> ServerStreamType + Send + Sync + 'static>( &mut self, connection_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn, ) -> Result<ConnectionChannel<StateType>, Box<dyn Error + Sync + Send>>

Spawns a task dedicated to the given “protocol processor”, returning immediately.
The given dialog_processor_builder_fn will be called for each new connection and should return a Stream that will produce non-futures & non-fallible items that may be, optionally, sent to the remote party (see crate::prelude::ResponsiveStream): Read more
Source§

async fn start_multi_protocol<ConnectionEventsCallbackFuture: Future<Output = ()> + Send>( &mut self, initial_connection_state: StateType, connection_routing_closure: impl FnMut(&SocketConnection<StateType>, bool) -> Option<Sender<SocketConnection<StateType>>> + Send + 'static, connection_events_callback: impl for<'r> Fn(ConnectionEvent<'r, StateType>) -> ConnectionEventsCallbackFuture + Send + 'static, ) -> Result<(), Box<dyn Error + Sync + Send>>

Starts the service using the provided connection_routing_closure to distribute the connections among the configured processors – previously fed in by [Self::spawn_responsive_processor()] & [Self::spawn_unresponsive_processor()]. Read more
Source§

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

Returns an async closure that blocks until Self::terminate() is called. Example: Read more
Source§

async fn terminate(self) -> Result<(), Box<dyn Error + Send + Sync>>

Notifies the service it is time to stop / shutdown / terminate.
It is a recommended practice that the connection_events_handler() you provided (when starting each dialog processor) inform all clients that a remote-initiated disconnection (due to the call to this function) is happening – the protocol must support that, though.
Source§

async fn start_single_protocol( &mut self, connection_channel: ConnectionChannel<Self::StateType>, ) -> Result<(), Box<dyn Error + Sync + Send>>
where Self::StateType: Default,

Start the service with a single processor (after calling either [Self::spawn_unresponsive_processor()] or [Self::spawn_responsive_processor()] once) – A.K.A. “The Single Protocol Mode”.
See Self::start_multi_protocol() if you want a service that shares connections among different protocol processors. Read more

Auto Trait Implementations§

§

impl<const CONFIG: u64, StateType> Freeze for CompositeSocketServer<CONFIG, StateType>

§

impl<const CONFIG: u64, StateType> !RefUnwindSafe for CompositeSocketServer<CONFIG, StateType>

§

impl<const CONFIG: u64, StateType> Send for CompositeSocketServer<CONFIG, StateType>

§

impl<const CONFIG: u64, StateType> Sync for CompositeSocketServer<CONFIG, StateType>

§

impl<const CONFIG: u64, StateType> Unpin for CompositeSocketServer<CONFIG, StateType>

§

impl<const CONFIG: u64, StateType> !UnwindSafe for CompositeSocketServer<CONFIG, StateType>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V