Trait samotop::service::TcpService [−][src]
pub trait TcpService { type Future: Future<Item = (), Error = ()>; fn handle(self, stream: TcpStream) -> Self::Future; }
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.
Associated Types
Required Methods
Implementors
impl<S, H> TcpService for SamotopService<S> where
S: SessionService<Handler = H>,
H: Send + 'static,
H: Sink<SinkItem = ServerControll, SinkError = Error>,
H: Stream<Item = ClientControll, Error = Error>, type Future = Box<Future<Item = (), Error = ()> + Send>;impl TcpService for DeadService type Future = FutureResult<(), ()>;