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
: theu64
version of the [ConstConfig] instance used to build this struct – from whichProcessorUniType
andSenderChannel
derive;RemoteMessages
: the messages that are generated by the clients (usually anenum
);LocalMessages
: the messages that are generated by the server (usually anenum
);ProcessorUniType
: an instance of areactive-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 areactive-mutiny
’s Uni movableChannel
, which will provide aStream
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§
Trait Implementations§
Source§impl<const CONFIG: u64, StateType: Send + Sync + Clone + Debug + 'static> MessagingService<CONFIG> for CompositeSocketServer<CONFIG, StateType>
impl<const CONFIG: u64, StateType: Send + Sync + Clone + Debug + 'static> MessagingService<CONFIG> for CompositeSocketServer<CONFIG, StateType>
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>>
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
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 moreSource§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>>
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 moreSource§fn termination_waiter(
&mut self,
) -> Box<dyn FnOnce() -> BoxFuture<'static, Result<(), Box<dyn Error + Send + Sync>>>>
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>>
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
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>>
async fn start_single_protocol( &mut self, connection_channel: ConnectionChannel<Self::StateType>, ) -> Result<(), Box<dyn Error + Sync + Send>>
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more