Fix warnings

This commit is contained in:
Carl Lerche
2017-08-24 15:52:01 -07:00
parent 638791ac6c
commit b0e6867877
26 changed files with 91 additions and 238 deletions

View File

@@ -56,7 +56,6 @@ impl<T, B> futures::Stream for Codec<T, B>
type Error = ConnectionError;
fn poll(&mut self) -> Poll<Option<Frame>, ConnectionError> {
use futures::Stream;
self.inner.poll()
}
}

View File

@@ -1,10 +1,9 @@
use {client, server, ConnectionError, Frame};
use HeaderMap;
use frame::{self, StreamId};
use {client, frame, server, ConnectionError};
use proto::*;
use http::{Request, Response};
use http::Request;
use futures::{Sink, Stream};
use bytes::{Bytes, IntoBuf};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -163,10 +162,10 @@ impl<T, P, B> Connection<T, P, B>
trace!("recv SETTINGS; frame={:?}", frame);
self.settings.recv_settings(frame);
}
Some(GoAway(frame)) => {
Some(GoAway(_)) => {
// TODO: handle the last_processed_id. Also, should this be
// handled as an error?
let e = ConnectionError::Proto(frame.reason());
// let _ = ConnectionError::Proto(frame.reason());
return Ok(().into());
}
Some(Ping(frame)) => {
@@ -220,21 +219,6 @@ impl<T, P, B> Connection<T, P, B>
}
}
}
fn convert_poll_message(frame: frame::Headers) -> Result<Frame<P::Poll>, ConnectionError> {
if frame.is_trailers() {
Ok(Frame::Trailers {
id: frame.stream_id(),
headers: frame.into_fields()
})
} else {
Ok(Frame::Headers {
id: frame.stream_id(),
end_of_stream: frame.is_end_stream(),
headers: P::convert_poll_message(frame)?,
})
}
}
}
impl<T, B> Connection<T, client::Peer, B>
@@ -261,13 +245,6 @@ impl<T, B> Connection<T, server::Peer, B>
// ====== impl State =====
impl State {
fn is_open(&self) -> bool {
match *self {
State::Open => true,
_ => false,
}
}
fn error(&self) -> Option<Reason> {
match *self {
State::Error(reason) => Some(reason),

View File

@@ -6,12 +6,12 @@ use error::Reason::*;
use futures::*;
use bytes::{Bytes, BytesMut};
use bytes::BytesMut;
use tokio_io::AsyncRead;
use tokio_io::codec::length_delimited;
use std::io::{self, Cursor};
use std::io;
#[derive(Debug)]
pub struct FramedRead<T> {

View File

@@ -1,12 +1,11 @@
use {hpack, ConnectionError, FrameSize};
use {hpack, ConnectionError};
use error::User::*;
use frame::{self, Frame};
use frame::{self, Frame, FrameSize};
use futures::*;
use tokio_io::{AsyncRead, AsyncWrite};
use bytes::{BytesMut, Buf, BufMut};
use std::cmp;
use std::io::{self, Cursor};
#[derive(Debug)]
@@ -176,9 +175,11 @@ impl<T, B> Sink for FramedWrite<T, B>
trace!("encoded window_update; rem={:?}", self.buf.remaining());
}
Frame::Priority(v) => {
// v.encode(self.buf.get_mut());
Frame::Priority(_) => {
/*
v.encode(self.buf.get_mut());
trace!("encoded priority; rem={:?}", self.buf.remaining());
*/
unimplemented!();
}
Frame::Reset(v) => {
@@ -210,7 +211,7 @@ impl<T, B> Sink for FramedWrite<T, B>
Some(Next::Data(frame)) => {
self.last_data_frame = Some(frame);
}
Some(Next::Continuation(frame)) => {
Some(Next::Continuation(_)) => {
unimplemented!();
}
None => {}

View File

@@ -16,11 +16,11 @@ use self::ping_pong::PingPong;
use self::settings::Settings;
use self::streams::Prioritized;
use {StreamId, ConnectionError};
use ConnectionError;
use error::Reason;
use frame::{self, Frame};
use frame::{self, Frame, StreamId};
use futures::{self, task, Poll, Async, AsyncSink, Sink, Stream as Stream2};
use futures::{self, task, Poll, Async, AsyncSink};
use futures::task::Task;
use bytes::{Buf, IntoBuf};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -50,12 +50,6 @@ pub type PingPayload = [u8; 8];
pub type WindowSize = u32;
#[derive(Debug, Copy, Clone)]
pub struct WindowUpdate {
stream_id: StreamId,
increment: WindowSize,
}
// Constants
pub const DEFAULT_INITIAL_WINDOW_SIZE: WindowSize = 65_535;
pub const MAX_WINDOW_SIZE: WindowSize = (1 << 31) - 1;
@@ -94,20 +88,3 @@ pub(crate) fn from_framed_write<T, P, B>(framed_write: FramedWrite<T, Prioritize
Connection::new(codec)
}
impl WindowUpdate {
pub fn new(stream_id: StreamId, increment: WindowSize) -> WindowUpdate {
WindowUpdate {
stream_id,
increment
}
}
pub fn stream_id(&self) -> StreamId {
self.stream_id
}
pub fn increment(&self) -> WindowSize {
self.increment
}
}

View File

@@ -2,6 +2,8 @@ use ConnectionError;
use frame::Ping;
use proto::*;
use futures::Sink;
/// Acknowledges ping requests from the remote.
#[derive(Debug)]
pub struct PingPong<B> {

View File

@@ -1,6 +1,8 @@
use {frame, ConnectionError};
use proto::*;
use futures::Sink;
#[derive(Debug)]
pub(crate) struct Settings {
/// Received SETTINGS frame pending processing. The ACK must be written to
@@ -45,7 +47,7 @@ impl Settings {
trace!("ACK sent");
dst.apply_remote_settings(settings);
streams.apply_remote_settings(settings);
streams.apply_remote_settings(settings)?;
}
self.pending = None;

View File

@@ -1,4 +1,4 @@
use frame::{self, Frame};
use frame::Frame;
use slab::Slab;

View File

@@ -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.

View File

@@ -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::*;

View File

@@ -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());

View File

@@ -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);
}

View File

@@ -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> {

View File

@@ -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::*;

View File

@@ -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 =====

View File

@@ -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;