tokio_proto/streaming/pipeline/
mod.rs

1//! Pipelined, streaming protocols.
2//!
3//! See the crate-level docs for an overview.
4
5use std::io;
6use futures::{Stream, Sink};
7use tokio_core::io as old_io;
8use tokio_io as new_io;
9
10mod frame;
11pub use self::frame::Frame;
12
13mod client;
14pub use self::client::ClientProto;
15
16mod server;
17pub use self::server::ServerProto;
18
19pub mod advanced;
20
21/// A marker used to flag protocols as being streaming and pipelined.
22///
23/// This is an implementation detail; to actually implement a protocol,
24/// implement the `ClientProto` or `ServerProto` traits in this module.
25#[derive(Debug)]
26pub struct StreamingPipeline<B>(B);
27
28/// Additional transport details relevant to streaming, pipelined protocols.
29///
30/// All methods added in this trait have default implementations.
31pub trait Transport: 'static +
32    Stream<Error = io::Error> +
33    Sink<SinkError = io::Error>
34{
35    /// Allow the transport to do miscellaneous work (e.g., sending ping-pong
36    /// messages) that is not directly connected to sending or receiving frames.
37    ///
38    /// This method should be called every time the task using the transport is
39    /// executing.
40    fn tick(&mut self) {}
41
42    /// Cancel interest in the current stream
43    fn cancel(&mut self) -> io::Result<()> {
44        Ok(())
45    }
46}
47
48impl<T, C> Transport for old_io::Framed<T,C>
49    where T: old_io::Io + 'static,
50          C: old_io::Codec + 'static,
51{}
52
53impl<T, C> Transport for new_io::codec::Framed<T,C>
54    where T: new_io::AsyncRead + new_io::AsyncWrite + 'static,
55          C: new_io::codec::Encoder<Error=io::Error> +
56                new_io::codec::Decoder<Error=io::Error> + 'static,
57{}