Fix warnings
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| use frame::{self, Frame}; | ||||
| use frame::Frame; | ||||
|  | ||||
| use slab::Slab; | ||||
|  | ||||
|   | ||||
| @@ -2,8 +2,6 @@ use ConnectionError; | ||||
| use proto::*; | ||||
| use error::Reason::*; | ||||
|  | ||||
| use std::cmp; | ||||
|  | ||||
| #[derive(Copy, Clone, Debug)] | ||||
| pub struct FlowControl { | ||||
|     /// Window size as indicated by the peer. This can go negative. | ||||
| @@ -49,21 +47,8 @@ impl FlowControl { | ||||
|         self.available -= capacity; | ||||
|     } | ||||
|  | ||||
|     pub fn assign_capacity(&mut self, capacity: WindowSize) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         let (val, overflow) = self.available.overflowing_add(capacity); | ||||
|  | ||||
|         if overflow { | ||||
|             return Err(FlowControlError.into()); | ||||
|         } | ||||
|  | ||||
|         if val > MAX_WINDOW_SIZE { | ||||
|             return Err(FlowControlError.into()); | ||||
|         } | ||||
|  | ||||
|         self.available = val; | ||||
|         Ok(()) | ||||
|     pub fn assign_capacity(&mut self, capacity: WindowSize) { | ||||
|         self.available + capacity; | ||||
|     } | ||||
|  | ||||
|     /// Returns the number of bytes available but not assigned to the window. | ||||
|   | ||||
| @@ -20,7 +20,8 @@ use self::state::State; | ||||
| use self::store::{Store, Entry}; | ||||
| use self::stream::Stream; | ||||
|  | ||||
| use {frame, StreamId, ConnectionError}; | ||||
| use {frame, ConnectionError}; | ||||
| use frame::StreamId; | ||||
| use proto::*; | ||||
| use error::Reason::*; | ||||
| use error::User::*; | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| use super::*; | ||||
|  | ||||
| use bytes::buf::Take; | ||||
| use futures::Sink; | ||||
|  | ||||
| use std::{fmt, cmp}; | ||||
|  | ||||
| @@ -40,8 +41,7 @@ impl<B> Prioritize<B> | ||||
|         flow.inc_window(config.init_local_window_sz) | ||||
|             .ok().expect("invalid initial window size"); | ||||
|  | ||||
|         flow.assign_capacity(config.init_local_window_sz) | ||||
|             .ok().expect("invalid initial window size"); | ||||
|         flow.assign_capacity(config.init_local_window_sz); | ||||
|  | ||||
|         Prioritize { | ||||
|             pending_send: store::Queue::new(), | ||||
| @@ -131,16 +131,13 @@ impl<B> Prioritize<B> | ||||
|     } | ||||
|  | ||||
|     /// Request capacity to send data | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize, stream: &mut store::Ptr<B>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize, stream: &mut store::Ptr<B>) { | ||||
|         // Actual capacity is `capacity` + the current amount of buffered data. | ||||
|         // It it were less, then we could never send out the buffered data. | ||||
|         let capacity = capacity + stream.buffered_send_data; | ||||
|  | ||||
|         if capacity == stream.requested_send_capacity { | ||||
|             // Nothing to do | ||||
|             return Ok(()); | ||||
|         } else if capacity < stream.requested_send_capacity { | ||||
|             // TODO: release capacity | ||||
|             unimplemented!(); | ||||
| @@ -152,8 +149,6 @@ impl<B> Prioritize<B> | ||||
|             // currently available, the stream will be queued to receive some | ||||
|             // when more becomes available. | ||||
|             self.try_assign_capacity(stream); | ||||
|  | ||||
|             Ok(()) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -184,7 +179,7 @@ impl<B> Prioritize<B> | ||||
|     { | ||||
|         // Update the connection's window | ||||
|         self.flow.inc_window(inc)?; | ||||
|         self.flow.assign_capacity(inc)?; | ||||
|         self.flow.assign_capacity(inc); | ||||
|  | ||||
|         // Assign newly acquired capacity to streams pending capacity. | ||||
|         while self.flow.available() > 0 { | ||||
| @@ -212,7 +207,7 @@ impl<B> Prioritize<B> | ||||
|  | ||||
|         // The amount of additional capacity that the stream requests. | ||||
|         // Don't assign more than the window has available! | ||||
|         let mut additional = cmp::min( | ||||
|         let additional = cmp::min( | ||||
|             total_requested - stream.send_flow.available(), | ||||
|             stream.send_flow.window_size()); | ||||
|  | ||||
|   | ||||
| @@ -3,8 +3,8 @@ use proto::*; | ||||
| use super::*; | ||||
|  | ||||
| use error::Reason::*; | ||||
| use futures::Sink; | ||||
|  | ||||
| use std::collections::VecDeque; | ||||
| use std::marker::PhantomData; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| @@ -58,7 +58,8 @@ impl<B> Recv<B> where B: Buf { | ||||
|  | ||||
|         let mut flow = FlowControl::new(); | ||||
|  | ||||
|         flow.inc_window(config.init_remote_window_sz); | ||||
|         flow.inc_window(config.init_remote_window_sz) | ||||
|             .ok().expect("invalid initial remote window size"); | ||||
|         flow.assign_capacity(config.init_remote_window_sz); | ||||
|  | ||||
|         Recv { | ||||
| @@ -127,7 +128,7 @@ impl<B> Recv<B> where B: Buf { | ||||
|                 // frame vs. now. | ||||
|                 Ok(client::Peer::convert_poll_message(v)?.into()) | ||||
|             } | ||||
|             Some(frame) => unimplemented!(), | ||||
|             Some(_) => unimplemented!(), | ||||
|             None => { | ||||
|                 stream.state.ensure_recv_open()?; | ||||
|  | ||||
| @@ -187,7 +188,7 @@ impl<B> Recv<B> where B: Buf { | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         // Transition the state | ||||
|         stream.state.recv_close(); | ||||
|         stream.state.recv_close()?; | ||||
|  | ||||
|         // Push the frame onto the stream's recv buffer | ||||
|         stream.pending_recv.push_back(&mut self.buffer, frame.into()); | ||||
| @@ -199,7 +200,6 @@ impl<B> Recv<B> where B: Buf { | ||||
|     pub fn release_capacity(&mut self, | ||||
|                             capacity: WindowSize, | ||||
|                             stream: &mut store::Ptr<B>, | ||||
|                             send: &mut Send<B>, | ||||
|                             task: &mut Option<Task>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
| @@ -315,7 +315,7 @@ impl<B> Recv<B> where B: Buf { | ||||
|             send.init_window_sz(), | ||||
|             self.init_window_sz); | ||||
|  | ||||
|         new_stream.state.reserve_remote(); | ||||
|         new_stream.state.reserve_remote()?; | ||||
|  | ||||
|         let mut ppp = store[stream].pending_push_promises.take(); | ||||
|  | ||||
| @@ -471,7 +471,7 @@ impl<B> Recv<B> where B: Buf { | ||||
|             let frame = frame::WindowUpdate::new(StreamId::zero(), incr); | ||||
|  | ||||
|             if dst.start_send(frame.into())?.is_ready() { | ||||
|                 self.flow.inc_window(incr); | ||||
|                 self.flow.inc_window(incr).ok().expect("unexpected flow control state"); | ||||
|             } else { | ||||
|                 return Ok(Async::NotReady); | ||||
|             } | ||||
|   | ||||
| @@ -7,9 +7,6 @@ use error::User::*; | ||||
|  | ||||
| use bytes::Buf; | ||||
|  | ||||
| use std::collections::VecDeque; | ||||
| use std::marker::PhantomData; | ||||
|  | ||||
| /// Manages state transitions related to outbound frames. | ||||
| #[derive(Debug)] | ||||
| pub(super) struct Send<B> { | ||||
| @@ -104,12 +101,6 @@ impl<B> Send<B> where B: Buf { | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     pub fn send_eos(&mut self, stream: &mut Stream<B>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         stream.state.send_close() | ||||
|     } | ||||
|  | ||||
|     pub fn send_reset(&mut self, reason: Reason, | ||||
|                       stream: &mut store::Ptr<B>, | ||||
|                       task: &mut Option<Task>) | ||||
| @@ -124,6 +115,7 @@ impl<B> Send<B> where B: Buf { | ||||
|  | ||||
|         let frame = frame::Reset::new(stream.id, reason); | ||||
|  | ||||
|         // TODO: This could impact connection level flow control. | ||||
|         self.prioritize.clear_queue(stream); | ||||
|  | ||||
|         trace!("send_reset -- queueing; frame={:?}", frame); | ||||
| @@ -151,9 +143,7 @@ impl<B> Send<B> where B: Buf { | ||||
|     } | ||||
|  | ||||
|     /// Request capacity to send data | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize, stream: &mut store::Ptr<B>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize, stream: &mut store::Ptr<B>) { | ||||
|         self.prioritize.reserve_capacity(capacity, stream) | ||||
|     } | ||||
|  | ||||
| @@ -211,6 +201,7 @@ impl<B> Send<B> where B: Buf { | ||||
|                                  settings: &frame::Settings, | ||||
|                                  store: &mut Store<B>, | ||||
|                                  task: &mut Option<Task>) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         if let Some(val) = settings.max_concurrent_streams() { | ||||
|             self.max_streams = Some(val as usize); | ||||
| @@ -251,15 +242,19 @@ impl<B> Send<B> where B: Buf { | ||||
|  | ||||
|                         // TODO: Should this notify the producer? | ||||
|                     } | ||||
|                 }); | ||||
|  | ||||
|                     Ok(()) | ||||
|                 })?; | ||||
|             } else if val > old_val { | ||||
|                 let inc = val - old_val; | ||||
|  | ||||
|                 store.for_each(|mut stream| { | ||||
|                     self.recv_stream_window_update(inc, &mut stream, task); | ||||
|                 }); | ||||
|                     self.recv_stream_window_update(inc, &mut stream, task) | ||||
|                 })?; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     pub fn ensure_not_idle(&self, id: StreamId) -> Result<(), ConnectionError> { | ||||
|   | ||||
| @@ -2,8 +2,6 @@ use ConnectionError; | ||||
| use error::Reason; | ||||
| use error::Reason::*; | ||||
| use error::User::*; | ||||
| use proto::*; | ||||
| use super::FlowControl; | ||||
|  | ||||
| use self::Inner::*; | ||||
| use self::Peer::*; | ||||
|   | ||||
| @@ -49,13 +49,12 @@ struct Indices { | ||||
| } | ||||
|  | ||||
| pub(super) enum Entry<'a, B: 'a> { | ||||
|     Occupied(OccupiedEntry<'a, B>), | ||||
|     Occupied(OccupiedEntry<'a>), | ||||
|     Vacant(VacantEntry<'a, B>), | ||||
| } | ||||
|  | ||||
| pub(super) struct OccupiedEntry<'a, B: 'a> { | ||||
| pub(super) struct OccupiedEntry<'a> { | ||||
|     ids: hash_map::OccupiedEntry<'a, StreamId, usize>, | ||||
|     slab: &'a mut slab::Slab<Stream<B>>, | ||||
| } | ||||
|  | ||||
| pub(super) struct VacantEntry<'a, B: 'a> { | ||||
| @@ -108,7 +107,6 @@ impl<B> Store<B> { | ||||
|             Occupied(e) => { | ||||
|                 Entry::Occupied(OccupiedEntry { | ||||
|                     ids: e, | ||||
|                     slab: &mut self.slab, | ||||
|                 }) | ||||
|             } | ||||
|             Vacant(e) => { | ||||
| @@ -120,15 +118,17 @@ impl<B> Store<B> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn for_each<F>(&mut self, mut f: F) | ||||
|         where F: FnMut(Ptr<B>) | ||||
|     pub fn for_each<F>(&mut self, mut f: F) -> Result<(), ConnectionError> | ||||
|         where F: FnMut(Ptr<B>) -> Result<(), ConnectionError>, | ||||
|     { | ||||
|         for &key in self.ids.values() { | ||||
|             f(Ptr { | ||||
|                 key: Key(key), | ||||
|                 slab: &mut self.slab, | ||||
|             }); | ||||
|             })?; | ||||
|         } | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -245,10 +245,6 @@ impl<'a, B: 'a> Ptr<'a, B> { | ||||
|             slab: &mut *self.slab, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn into_mut(self) -> &'a mut Stream<B> { | ||||
|         &mut self.slab[self.key.0] | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, B: 'a> ops::Deref for Ptr<'a, B> { | ||||
| @@ -267,22 +263,10 @@ impl<'a, B: 'a> ops::DerefMut for Ptr<'a, B> { | ||||
|  | ||||
| // ===== impl OccupiedEntry ===== | ||||
|  | ||||
| impl<'a, B> OccupiedEntry<'a, B> { | ||||
| impl<'a> OccupiedEntry<'a> { | ||||
|     pub fn key(&self) -> Key { | ||||
|         Key(*self.ids.get()) | ||||
|     } | ||||
|  | ||||
|     pub fn get(&self) -> &Stream<B> { | ||||
|         &self.slab[*self.ids.get()] | ||||
|     } | ||||
|  | ||||
|     pub fn get_mut(&mut self) -> &mut Stream<B> { | ||||
|         &mut self.slab[*self.ids.get()] | ||||
|     } | ||||
|  | ||||
|     pub fn into_mut(self) -> &'a mut Stream<B> { | ||||
|         &mut self.slab[*self.ids.get()] | ||||
|     } | ||||
| } | ||||
|  | ||||
| // ===== impl VacantEntry ===== | ||||
|   | ||||
| @@ -2,7 +2,6 @@ use {client, server}; | ||||
| use proto::*; | ||||
| use super::*; | ||||
|  | ||||
| use std::marker::PhantomData; | ||||
| use std::sync::{Arc, Mutex}; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| @@ -134,7 +133,7 @@ impl<B> Streams<B> | ||||
|             return Err(ProtocolError.into()); | ||||
|         } | ||||
|  | ||||
|         let mut stream = match me.store.find_mut(&id) { | ||||
|         let stream = match me.store.find_mut(&id) { | ||||
|             Some(stream) => stream, | ||||
|             None => { | ||||
|                 // TODO: Are there other error cases? | ||||
| @@ -159,8 +158,9 @@ impl<B> Streams<B> | ||||
|         let last_processed_id = actions.recv.last_processed_id(); | ||||
|  | ||||
|         me.store.for_each(|mut stream| { | ||||
|             actions.recv.recv_err(err, &mut *stream) | ||||
|         }); | ||||
|             actions.recv.recv_err(err, &mut *stream); | ||||
|             Ok(()) | ||||
|         }).ok().expect("unexpected error processing error"); | ||||
|  | ||||
|         last_processed_id | ||||
|     } | ||||
| @@ -180,7 +180,7 @@ impl<B> Streams<B> | ||||
|             // considers closed. It's ok... | ||||
|             if let Some(mut stream) = me.store.find_mut(&id) { | ||||
|                 me.actions.send.recv_stream_window_update( | ||||
|                     frame.size_increment(), &mut stream, &mut me.actions.task); | ||||
|                     frame.size_increment(), &mut stream, &mut me.actions.task)?; | ||||
|             } else { | ||||
|                 me.actions.recv.ensure_not_idle(id)?; | ||||
|             } | ||||
| @@ -197,7 +197,7 @@ impl<B> Streams<B> | ||||
|  | ||||
|         let id = frame.stream_id(); | ||||
|  | ||||
|         let mut stream = match me.store.find_mut(&id) { | ||||
|         let stream = match me.store.find_mut(&id) { | ||||
|             Some(stream) => stream.key(), | ||||
|             None => return Err(ProtocolError.into()), | ||||
|         }; | ||||
| @@ -253,12 +253,14 @@ impl<B> Streams<B> | ||||
|         Ok(().into()) | ||||
|     } | ||||
|  | ||||
|     pub fn apply_remote_settings(&mut self, frame: &frame::Settings) { | ||||
|     pub fn apply_remote_settings(&mut self, frame: &frame::Settings) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|         let mut me = self.inner.lock().unwrap(); | ||||
|         let me = &mut *me; | ||||
|  | ||||
|         me.actions.send.apply_remote_settings( | ||||
|             frame, &mut me.store, &mut me.actions.task); | ||||
|             frame, &mut me.store, &mut me.actions.task) | ||||
|     } | ||||
|  | ||||
|     pub fn poll_send_request_ready(&mut self) -> Poll<(), ConnectionError> { | ||||
| @@ -412,13 +414,11 @@ impl<B> StreamRef<B> | ||||
|         let mut stream = me.store.resolve(self.key); | ||||
|  | ||||
|         me.actions.recv.release_capacity( | ||||
|             capacity, &mut stream, &mut me.actions.send, &mut me.actions.task) | ||||
|             capacity, &mut stream, &mut me.actions.task) | ||||
|     } | ||||
|  | ||||
|     /// Request capacity to send data | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize) | ||||
|         -> Result<(), ConnectionError> | ||||
|     { | ||||
|     pub fn reserve_capacity(&mut self, capacity: WindowSize) { | ||||
|         let mut me = self.inner.lock().unwrap(); | ||||
|         let me = &mut *me; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user