pub struct TcpServerRouter<C>where
C: Encoder<Bytes, Error = Error> + Decoder<Item = BytesMut, Error = Error> + Clone + Send + Sync + 'static + TfCodec,{ /* private fields */ }Expand description
Tcp server router. Handles the every data route destination
Implementations§
Source§impl<C> TcpServerRouter<C>
impl<C> TcpServerRouter<C>
Sourcepub fn new(user_s_type: Box<dyn StructureType>) -> Self
pub fn new(user_s_type: Box<dyn StructureType>) -> Self
Returns the new instance of router
‘user_s_type’ random enum value of current project defined structure_type
Sourcepub fn add_route(
&mut self,
handler: Arc<Mutex<dyn Handler<Codec = C>>>,
handler_name: String,
s_types: Vec<Box<dyn StructureType>>,
)
pub fn add_route( &mut self, handler: Arc<Mutex<dyn Handler<Codec = C>>>, handler_name: String, s_types: Vec<Box<dyn StructureType>>, )
Registers the new handler, for selected structure types
‘handler_name’ must be the same on the client site, used for initial identification. When client sends request to server. ‘s_type’ handled structure types by current handler.
Sourcepub fn commit_routes(&mut self)
pub fn commit_routes(&mut self)
Commits the registered handlers. Making the current router is final and ready to be passed to the server
pub fn get_routes( &self, ) -> Arc<HashMap<TypeTupple, Arc<Mutex<dyn Handler<Codec = C>>>>>
Sourcepub async fn serve_packet(
&self,
meta: BytesMut,
payload: BytesMut,
client_meta: (SocketAddr, &mut Option<Sender<Arc<Mutex<dyn Handler<Codec = C>>>>>),
) -> Result<Vec<u8>, ServerError>
pub async fn serve_packet( &self, meta: BytesMut, payload: BytesMut, client_meta: (SocketAddr, &mut Option<Sender<Arc<Mutex<dyn Handler<Codec = C>>>>>), ) -> Result<Vec<u8>, ServerError>
Called from server connection task
Auto Trait Implementations§
impl<C> Freeze for TcpServerRouter<C>
impl<C> !RefUnwindSafe for TcpServerRouter<C>
impl<C> Send for TcpServerRouter<C>
impl<C> Sync for TcpServerRouter<C>
impl<C> Unpin for TcpServerRouter<C>
impl<C> !UnwindSafe for TcpServerRouter<C>
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