[−][src]Trait ckb_network::ServiceProtocol
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
pub fn init(&mut self, context: &mut ProtocolContext)
[src]
This function is called when the service start.
The service handle will only be called once
Provided methods
pub fn connected(&mut self, _context: ProtocolContextMutRef<'_>, _version: &str)
[src]
Called when opening protocol
pub fn disconnected(&mut self, _context: ProtocolContextMutRef<'_>)
[src]
Called when closing protocol
pub fn received(&mut self, _context: ProtocolContextMutRef<'_>, _data: Bytes)
[src]
Called when the corresponding protocol message is received
pub fn notify(&mut self, _context: &mut ProtocolContext, _token: u64)
[src]
Called when the Service receives the notify task
pub fn poll(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_context: &mut ProtocolContext
) -> Poll<Option<()>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_context: &mut ProtocolContext
) -> Poll<Option<()>>
Behave like Stream::poll_next
, but nothing output
if ready with Some, it will continue poll immediately
if ready with None, it will don't try to call the function again
Implementations on Foreign Types
impl ServiceProtocol for Box<dyn ServiceProtocol + 'static + Unpin + Send, Global>
[src]
pub fn init(&mut self, context: &mut ProtocolContext)
[src]
pub fn connected(&mut self, context: ProtocolContextMutRef<'_>, version: &str)
[src]
pub fn disconnected(&mut self, context: ProtocolContextMutRef<'_>)
[src]
pub fn received(&mut self, context: ProtocolContextMutRef<'_>, data: Bytes)
[src]
pub fn notify(&mut self, context: &mut ProtocolContext, token: u64)
[src]
pub fn poll(
self: Pin<&mut Box<dyn ServiceProtocol + 'static + Unpin + Send, Global>>,
cx: &mut Context<'_>,
context: &mut ProtocolContext
) -> Poll<Option<()>>
[src]
self: Pin<&mut Box<dyn ServiceProtocol + 'static + Unpin + Send, Global>>,
cx: &mut Context<'_>,
context: &mut ProtocolContext
) -> Poll<Option<()>>
impl ServiceProtocol for Box<dyn ServiceProtocol + 'static + Unpin + Send + Sync, Global>
[src]
pub fn init(&mut self, context: &mut ProtocolContext)
[src]
pub fn connected(&mut self, context: ProtocolContextMutRef<'_>, version: &str)
[src]
pub fn disconnected(&mut self, context: ProtocolContextMutRef<'_>)
[src]
pub fn received(&mut self, context: ProtocolContextMutRef<'_>, data: Bytes)
[src]
pub fn notify(&mut self, context: &mut ProtocolContext, token: u64)
[src]
pub fn poll(
self: Pin<&mut Box<dyn ServiceProtocol + 'static + Unpin + Send + Sync, Global>>,
cx: &mut Context<'_>,
context: &mut ProtocolContext
) -> Poll<Option<()>>
[src]
self: Pin<&mut Box<dyn ServiceProtocol + 'static + Unpin + Send + Sync, Global>>,
cx: &mut Context<'_>,
context: &mut ProtocolContext
) -> Poll<Option<()>>