Get receiving data working

This commit is contained in:
Carl Lerche
2017-08-07 12:48:50 -07:00
parent 71acfe3961
commit 6053ee059d
5 changed files with 86 additions and 39 deletions

View File

@@ -3,7 +3,7 @@ use proto::{self, Connection};
use error::Reason::*;
use http::{self, Request, Response};
use futures::{Future, Poll, Sink, AsyncSink};
use futures::{self, Future, Poll, Sink, AsyncSink};
use tokio_io::{AsyncRead, AsyncWrite};
use bytes::{Bytes, IntoBuf};
@@ -99,6 +99,19 @@ impl<T, B> Client<T, B>
}
}
impl<T, B> Future for Client<T, B>
// TODO: Get rid of 'static
where T: AsyncRead + AsyncWrite + 'static,
B: IntoBuf + 'static,
{
type Item = ();
type Error = ConnectionError;
fn poll(&mut self) -> Poll<(), ConnectionError> {
self.connection.poll()
}
}
impl<T, B> fmt::Debug for Client<T, B>
where T: fmt::Debug,
B: fmt::Debug + IntoBuf,
@@ -167,6 +180,28 @@ impl<B: IntoBuf> Future for Stream<B> {
}
}
// ===== impl Body =====
impl<B: IntoBuf> futures::Stream for Body<B> {
type Item = Chunk<B>;
type Error = ConnectionError;
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
let chunk = try_ready!(self.inner.poll_data())
.map(|inner| Chunk { inner });
Ok(chunk.into())
}
}
// ===== impl Chunk =====
impl<B: IntoBuf> Chunk<B> {
pub fn pop_bytes(&mut self) -> Option<Bytes> {
self.inner.pop_bytes()
}
}
// ===== impl Peer =====
impl proto::Peer for Peer {