More code
This commit is contained in:
		| @@ -91,7 +91,7 @@ impl<T, P, B> Connection<T, P, B> | ||||
|     } | ||||
|  | ||||
|     /// Advances the internal state of the connection. | ||||
|     pub fn poll(&mut self) -> Poll<Option<()>, ConnectionError> { | ||||
|     pub fn poll(&mut self) -> Poll<(), ConnectionError> { | ||||
|         use frame::Frame::*; | ||||
|  | ||||
|         loop { | ||||
| @@ -183,11 +183,9 @@ impl<T, P, B> Connection<T, P, B> | ||||
|                     */ | ||||
|                 } | ||||
|                 None => { | ||||
|                     unimplemented!(); | ||||
|                     /* | ||||
|                     // TODO: Is this correct? | ||||
|                     trace!("codec closed"); | ||||
|                     return Ok(Async::Ready(None)); | ||||
|                     */ | ||||
|                     return Ok(Async::Ready(())); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -18,7 +18,7 @@ pub struct Deque<B> { | ||||
| } | ||||
|  | ||||
| /// Tracks the head & tail for a sequence of frames in a `Buffer`. | ||||
| #[derive(Debug, Default)] | ||||
| #[derive(Debug, Default, Copy, Clone)] | ||||
| struct Indices { | ||||
|     head: usize, | ||||
|     tail: usize, | ||||
| @@ -27,7 +27,7 @@ struct Indices { | ||||
| #[derive(Debug)] | ||||
| struct Slot<B> { | ||||
|     frame: Frame<B>, | ||||
|     next: usize, | ||||
|     next: Option<usize>, | ||||
| } | ||||
|  | ||||
| impl<B> Buffer<B> { | ||||
| @@ -50,11 +50,42 @@ impl<B> Deque<B> { | ||||
|         self.indices.is_none() | ||||
|     } | ||||
|  | ||||
|     pub fn push_back(&mut self, buf: &mut Buffer<B>, val: Frame<B>) { | ||||
|         unimplemented!(); | ||||
|     pub fn push_back(&mut self, buf: &mut Buffer<B>, frame: Frame<B>) { | ||||
|         let key = buf.slab.insert(Slot { | ||||
|             frame, | ||||
|             next: None, | ||||
|         }); | ||||
|  | ||||
|         match self.indices { | ||||
|             Some(ref mut idxs) => { | ||||
|                 buf.slab[idxs.tail].next = Some(key); | ||||
|                 idxs.tail = key; | ||||
|             } | ||||
|             None => { | ||||
|                 self.indices = Some(Indices { | ||||
|                     head: key, | ||||
|                     tail: key, | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn pop_front(&mut self, buf: &mut Buffer<B>) -> Option<Frame<B>> { | ||||
|         unimplemented!(); | ||||
|         match self.indices { | ||||
|             Some(mut idxs) => { | ||||
|                 let mut slot = buf.slab.remove(idxs.head); | ||||
|  | ||||
|                 if idxs.head == idxs.tail { | ||||
|                     assert!(slot.next.is_none()); | ||||
|                     self.indices = None; | ||||
|                 } else { | ||||
|                     idxs.head = slot.next.take().unwrap(); | ||||
|                     self.indices = Some(idxs); | ||||
|                 } | ||||
|  | ||||
|                 return Some(slot.frame); | ||||
|             } | ||||
|             None => None, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -38,27 +38,8 @@ impl<B> Prioritize<B> | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // The next pointer shouldn't be set | ||||
|         debug_assert!(stream.next_pending_send.is_none()); | ||||
|  | ||||
|         // Queue the stream | ||||
|         match self.pending_send { | ||||
|             Some(ref mut idxs) => { | ||||
|                 // Update the current tail node to point to `stream` | ||||
|                 stream.resolve(idxs.tail).next_pending_send = Some(stream.key()); | ||||
|  | ||||
|                 // Update the tail pointer | ||||
|                 idxs.tail = stream.key(); | ||||
|             } | ||||
|             None => { | ||||
|                 self.pending_send = Some(Indices { | ||||
|                     head: stream.key(), | ||||
|                     tail: stream.key(), | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         stream.is_pending_send = true; | ||||
|         self.push_sender(stream); | ||||
|     } | ||||
|  | ||||
|     pub fn poll_complete<T>(&mut self, | ||||
| @@ -88,6 +69,59 @@ impl<B> Prioritize<B> | ||||
|     } | ||||
|  | ||||
|     fn pop_frame(&mut self, store: &mut Store<B>) -> Option<Frame<B>> { | ||||
|         unimplemented!(); | ||||
|         match self.pop_sender(store) { | ||||
|             Some(mut stream) => { | ||||
|                 let frame = stream.pending_send.pop_front(&mut self.buffer).unwrap(); | ||||
|  | ||||
|                 if !stream.pending_send.is_empty() { | ||||
|                     self.push_sender(&mut stream); | ||||
|                 } | ||||
|  | ||||
|                 Some(frame) | ||||
|             } | ||||
|             None => None, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn push_sender(&mut self, stream: &mut store::Ptr<B>) { | ||||
|         // The next pointer shouldn't be set | ||||
|         debug_assert!(stream.next_pending_send.is_none()); | ||||
|  | ||||
|         // Queue the stream | ||||
|         match self.pending_send { | ||||
|             Some(ref mut idxs) => { | ||||
|                 // Update the current tail node to point to `stream` | ||||
|                 stream.resolve(idxs.tail).next_pending_send = Some(stream.key()); | ||||
|  | ||||
|                 // Update the tail pointer | ||||
|                 idxs.tail = stream.key(); | ||||
|             } | ||||
|             None => { | ||||
|                 self.pending_send = Some(Indices { | ||||
|                     head: stream.key(), | ||||
|                     tail: stream.key(), | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         stream.is_pending_send = true; | ||||
|     } | ||||
|  | ||||
|     fn pop_sender<'a>(&mut self, store: &'a mut Store<B>) -> Option<store::Ptr<'a, B>> { | ||||
|         if let Some(mut idxs) = self.pending_send { | ||||
|             let mut stream = store.resolve(idxs.head); | ||||
|  | ||||
|             if idxs.head == idxs.tail { | ||||
|                 assert!(stream.next_pending_send.is_none()); | ||||
|                 self.pending_send = None; | ||||
|             } else { | ||||
|                 idxs.head = stream.next_pending_send.take().unwrap(); | ||||
|                 self.pending_send = Some(idxs); | ||||
|             } | ||||
|  | ||||
|             return Some(stream); | ||||
|         } | ||||
|  | ||||
|         None | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -19,7 +19,7 @@ pub(super) struct Ptr<'a, B: 'a> { | ||||
| } | ||||
|  | ||||
| /// References an entry in the store. | ||||
| #[derive(Debug, Clone, Copy)] | ||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||||
| pub(super) struct Key(usize); | ||||
|  | ||||
| pub(super) enum Entry<'a, B: 'a> { | ||||
|   | ||||
| @@ -271,6 +271,11 @@ impl<B> Streams<client::Peer, B> | ||||
|     pub fn send_request(&mut self, request: Request<()>, end_of_stream: bool) | ||||
|         -> Result<StreamRef<client::Peer, B>, ConnectionError> | ||||
|     { | ||||
|         // TODO: There is a hazard with assigning a stream ID before the | ||||
|         // prioritize layer. If prioritization reorders new streams, this | ||||
|         // implicitly closes the earlier stream IDs. | ||||
|         // | ||||
|         // See: carllerche/h2#11 | ||||
|         let key = { | ||||
|             let mut me = self.inner.lock().unwrap(); | ||||
|             let me = &mut *me; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user