Trait tentacle::traits::ServiceProtocol [−][src]
pub trait ServiceProtocol {
fn init(&mut self, context: &mut ProtocolContext);
fn connected(&mut self, _context: ProtocolContextMutRef<'_>, _version: &str) { ... }
fn disconnected(&mut self, _context: ProtocolContextMutRef<'_>) { ... }
fn received(&mut self, _context: ProtocolContextMutRef<'_>, _data: Bytes) { ... }
fn notify(&mut self, _context: &mut ProtocolContext, _token: u64) { ... }
fn poll(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_context: &mut ProtocolContext
) -> Poll<Option<()>> { ... }
}
Expand description
Service level protocol handle
Note
All functions on this trait will block the entire server running, do not insert long-time tasks, you can use the futures task instead.
Behavior
Define the behavior of each custom protocol in each state.
Depending on whether the user defines a service handle or a session exclusive handle, the runtime has different performance.
The important difference is that some state values are allowed in the service handle, and the handle exclusive to the session is “stateless”, relative to the service handle, it can only retain the information between a protocol stream on and off.
The opening and closing of the protocol will create and clean up the handle exclusive to the session, but the service handle will remain in the state until the service is closed.
Required methods
fn init(&mut self, context: &mut ProtocolContext)
fn init(&mut self, context: &mut ProtocolContext)
This function is called when the service start.
The service handle will only be called once
Provided methods
fn connected(&mut self, _context: ProtocolContextMutRef<'_>, _version: &str)
fn connected(&mut self, _context: ProtocolContextMutRef<'_>, _version: &str)
Called when opening protocol
fn disconnected(&mut self, _context: ProtocolContextMutRef<'_>)
fn disconnected(&mut self, _context: ProtocolContextMutRef<'_>)
Called when closing protocol
fn received(&mut self, _context: ProtocolContextMutRef<'_>, _data: Bytes)
fn received(&mut self, _context: ProtocolContextMutRef<'_>, _data: Bytes)
Called when the corresponding protocol message is received
fn notify(&mut self, _context: &mut ProtocolContext, _token: u64)
fn notify(&mut self, _context: &mut ProtocolContext, _token: u64)
Called when the Service receives the notify task