Start hooking up sending data
This commit is contained in:
		| @@ -73,7 +73,7 @@ impl<P, B> Recv<P, B> | ||||
|         // Increment the number of remote initiated streams | ||||
|         self.num_streams += 1; | ||||
|  | ||||
|         Ok(Some(Stream::new())) | ||||
|         Ok(Some(Stream::new(id))) | ||||
|     } | ||||
|  | ||||
|     /// Transition the stream state based on receiving headers | ||||
|   | ||||
| @@ -67,7 +67,7 @@ impl<P, B> Send<P, B> | ||||
|     /// Update state reflecting a new, locally opened stream | ||||
|     /// | ||||
|     /// Returns the stream state if successful. `None` if refused | ||||
|     pub fn open(&mut self) -> Result<(StreamId, Stream<B>), ConnectionError> { | ||||
|     pub fn open(&mut self) -> Result<Stream<B>, ConnectionError> { | ||||
|         try!(self.ensure_can_open()); | ||||
|  | ||||
|         if let Some(max) = self.max_streams { | ||||
| @@ -76,7 +76,7 @@ impl<P, B> Send<P, B> | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         let ret = (self.next_stream_id, Stream::new()); | ||||
|         let ret = Stream::new(self.next_stream_id); | ||||
|  | ||||
|         // Increment the number of locally initiated streams | ||||
|         self.num_streams += 1; | ||||
| @@ -106,8 +106,8 @@ impl<P, B> Send<P, B> | ||||
|     } | ||||
|  | ||||
|     pub fn send_data(&mut self, | ||||
|                      frame: &frame::Data<B>, | ||||
|                      stream: &mut Stream<B>) | ||||
|                      frame: frame::Data<B>, | ||||
|                      stream: &mut store::Ptr<B>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         let sz = frame.payload().remaining(); | ||||
| @@ -148,6 +148,8 @@ impl<P, B> Send<P, B> | ||||
|             try!(stream.state.send_close()); | ||||
|         } | ||||
|  | ||||
|         self.prioritize.queue_frame(frame.into(), stream); | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,9 @@ use super::*; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| pub(super) struct Stream<B> { | ||||
|     /// The h2 stream identifier | ||||
|     pub id: StreamId, | ||||
|  | ||||
|     /// Current state of the stream | ||||
|     pub state: State, | ||||
|  | ||||
| @@ -22,8 +25,9 @@ pub(super) struct Stream<B> { | ||||
| } | ||||
|  | ||||
| impl<B> Stream<B> { | ||||
|     pub fn new() -> Stream<B> { | ||||
|     pub fn new(id: StreamId) -> Stream<B> { | ||||
|         Stream { | ||||
|             id, | ||||
|             state: State::default(), | ||||
|             pending_recv: buffer::Deque::new(), | ||||
|             recv_task: None, | ||||
|   | ||||
| @@ -200,6 +200,7 @@ impl<P, B> Streams<P, B> | ||||
|         */ | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|     pub fn send_data(&mut self, frame: &frame::Data<B>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
| @@ -222,6 +223,7 @@ impl<P, B> Streams<P, B> | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|     */ | ||||
|  | ||||
|     pub fn poll_window_update(&mut self) | ||||
|         -> Poll<WindowUpdate, ConnectionError> | ||||
| @@ -290,13 +292,13 @@ impl<B> Streams<client::Peer, B> | ||||
|             let me = &mut *me; | ||||
|  | ||||
|             // Initialize a new stream. This fails if the connection is at capacity. | ||||
|             let (id, mut stream) = me.actions.send.open()?; | ||||
|             let mut stream = me.actions.send.open()?; | ||||
|  | ||||
|             // Convert the message | ||||
|             let headers = client::Peer::convert_send_message( | ||||
|                 id, request, end_of_stream); | ||||
|                 stream.id, request, end_of_stream); | ||||
|  | ||||
|             let mut stream = me.store.insert(id, stream); | ||||
|             let mut stream = me.store.insert(stream.id, stream); | ||||
|  | ||||
|             me.actions.send.send_headers(headers, &mut stream)?; | ||||
|  | ||||
| @@ -320,6 +322,27 @@ impl<P, B> StreamRef<P, B> | ||||
|     where P: Peer, | ||||
|           B: Buf, | ||||
| { | ||||
|     pub fn send_data(&mut self, data: B, end_of_stream: bool) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         let mut me = self.inner.lock().unwrap(); | ||||
|         let me = &mut *me; | ||||
|  | ||||
|         let mut stream = me.store.resolve(self.key); | ||||
|  | ||||
|         // Create the data frame | ||||
|         let frame = frame::Data::from_buf(stream.id, data, end_of_stream); | ||||
|  | ||||
|         // Send the data frame | ||||
|         me.actions.send.send_data(frame, &mut stream)?; | ||||
|  | ||||
|         if stream.state.is_closed() { | ||||
|             me.actions.dec_num_streams(stream.id); | ||||
|         } | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     pub fn poll_data(&mut self) -> Poll<Option<Chunk<P, B>>, ConnectionError> { | ||||
|         let recv = { | ||||
|             let mut me = self.inner.lock().unwrap(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user