Get receiving data working
This commit is contained in:
		| @@ -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 { | ||||
|   | ||||
| @@ -236,8 +236,12 @@ impl<P, B> Recv<P, B> | ||||
|             .take_while(&mut self.buffer, |frame| frame.is_data()); | ||||
|  | ||||
|         if frames.is_empty() { | ||||
|             stream.recv_task = Some(task::current()); | ||||
|             Ok(Async::NotReady) | ||||
|             if stream.state.is_recv_closed() { | ||||
|                 Ok(None.into()) | ||||
|             } else { | ||||
|                 stream.recv_task = Some(task::current()); | ||||
|                 Ok(Async::NotReady) | ||||
|             } | ||||
|         } else { | ||||
|             Ok(Some(Chunk { | ||||
|                 pending_recv: frames, | ||||
|   | ||||
| @@ -203,6 +203,13 @@ impl State { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn is_recv_closed(&self) -> bool { | ||||
|         match self.inner { | ||||
|             Closed(..) | HalfClosedRemote(..) => true, | ||||
|             _ => false, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn recv_flow_control(&mut self) -> Option<&mut FlowControl> { | ||||
|         match self.inner { | ||||
|             Open { ref mut remote, .. } | | ||||
|   | ||||
| @@ -368,6 +368,19 @@ impl<P, B> Clone for StreamRef<P, B> { | ||||
|  | ||||
| // ===== impl Chunk ===== | ||||
|  | ||||
| impl<P, B> Chunk<P, B> | ||||
|     where P: Peer, | ||||
|           B: Buf, | ||||
| { | ||||
|     // TODO: Come up w/ a better API | ||||
|     pub fn pop_bytes(&mut self) -> Option<Bytes> { | ||||
|         let mut me = self.inner.lock().unwrap(); | ||||
|         let me = &mut *me; | ||||
|  | ||||
|         me.actions.recv.pop_bytes(&mut self.recv) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<P, B> Drop for Chunk<P, B> | ||||
|     where P: Peer, | ||||
|           B: Buf, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user