Trait samotop::service::TcpService
source · pub trait TcpService {
type Future: Future<Item = (), Error = ()>;
fn handle(self, stream: TcpStream) -> Self::Future;
}
Expand description
An object implementing this trait handles TCP connections in a Future
.
The caller would ask the service to handle()
the TcpStream
,
then poll the returned future or more likely tokio::spawn()
it.
Here’s a dead simple implementation that returns a completed future and doesn’t do anything with the stream:
#[derive(Clone, Debug)]
pub struct DeadService;
impl TcpService for DeadService {
type Future = FutureResult<(), ()>;
fn handle(self, _stream: TcpStream) -> Self::Future {
future::ok(()) // or do something with the stream
}
}
You can then use this DeadService
in samotop:
let task = samotop::builder()
.with(DeadService)
.build_task();
The SamotopService
implements this trait.