This commit is contained in:
Carl Lerche
2017-03-10 18:38:06 -08:00
parent 0e35254bd8
commit f19f039bbc
4 changed files with 160 additions and 77 deletions

47
src/proto/ping_pong.rs Normal file
View File

@@ -0,0 +1,47 @@
use ConnectionError;
use frame::Frame;
use futures::*;
pub struct PingPong<T> {
inner: T,
}
impl<T> PingPong<T>
where T: Stream<Item = Frame, Error = ConnectionError>,
T: Sink<SinkItem = Frame, SinkError = ConnectionError>,
{
pub fn new(inner: T) -> PingPong<T> {
PingPong {
inner: inner,
}
}
}
impl<T> Stream for PingPong<T>
where T: Stream<Item = Frame, Error = ConnectionError>,
T: Sink<SinkItem = Frame, SinkError = ConnectionError>,
{
type Item = Frame;
type Error = ConnectionError;
fn poll(&mut self) -> Poll<Option<Frame>, ConnectionError> {
self.inner.poll()
}
}
impl<T> Sink for PingPong<T>
where T: Stream<Item = Frame, Error = ConnectionError>,
T: Sink<SinkItem = Frame, SinkError = ConnectionError>,
{
type SinkItem = Frame;
type SinkError = ConnectionError;
fn start_send(&mut self, item: Frame) -> StartSend<Frame, ConnectionError> {
self.inner.start_send(item)
}
fn poll_complete(&mut self) -> Poll<(), ConnectionError> {
self.inner.poll_complete()
}
}