chore: cargo fmt, clippy

This commit is contained in:
Gurwinder Singh
2019-08-17 09:07:32 +05:30
committed by Sean McArthur
parent e72d6dc189
commit f46840f3fa
43 changed files with 785 additions and 870 deletions

View File

@@ -1,5 +1,5 @@
use super::*;
use super::store::Resolve;
use super::*;
use crate::frame::{Reason, StreamId};
@@ -8,9 +8,9 @@ use crate::codec::UserError::*;
use bytes::buf::Take;
use futures::ready;
use std::{cmp, fmt, mem};
use std::io;
use std::task::{Context, Poll, Waker};
use std::{cmp, fmt, mem};
/// # Warning
///
@@ -81,7 +81,6 @@ impl Prioritize {
let mut flow = FlowControl::new();
flow.inc_window(config.remote_init_window_sz)
.ok()
.expect("invalid initial window size");
flow.assign_capacity(config.remote_init_window_sz);
@@ -92,7 +91,7 @@ impl Prioritize {
pending_send: store::Queue::new(),
pending_capacity: store::Queue::new(),
pending_open: store::Queue::new(),
flow: flow,
flow,
last_opened_id: StreamId::ZERO,
in_flight_data_frame: InFlightData::Nothing,
}
@@ -203,9 +202,7 @@ impl Prioritize {
// The stream has no capacity to send the frame now, save it but
// don't notify the connection task. Once additional capacity
// becomes available, the frame will be flushed.
stream
.pending_send
.push_back(buffer, frame.into());
stream.pending_send.push_back(buffer, frame.into());
}
Ok(())
@@ -216,7 +213,8 @@ impl Prioritize {
&mut self,
capacity: WindowSize,
stream: &mut store::Ptr,
counts: &mut Counts) {
counts: &mut Counts,
) {
log::trace!(
"reserve_capacity; stream={:?}; requested={:?}; effective={:?}; curr={:?}",
stream.id,
@@ -338,8 +336,8 @@ impl Prioritize {
&mut self,
inc: WindowSize,
store: &mut R,
counts: &mut Counts)
where
counts: &mut Counts,
) where
R: Resolve,
{
log::trace!("assign_connection_capacity; inc={}", inc);
@@ -419,11 +417,7 @@ impl Prioritize {
// TODO: Should prioritization factor into this?
let assign = cmp::min(conn_available, additional);
log::trace!(
" assigning; stream={:?}, capacity={}",
stream.id,
assign,
);
log::trace!(" assigning; stream={:?}, capacity={}", stream.id, assign,);
// Assign the capacity to the stream
stream.assign_capacity(assign);
@@ -440,16 +434,16 @@ impl Prioritize {
stream.send_flow.has_unavailable()
);
if stream.send_flow.available() < stream.requested_send_capacity {
if stream.send_flow.has_unavailable() {
// The stream requires additional capacity and the stream's
// window has available capacity, but the connection window
// does not.
//
// In this case, the stream needs to be queued up for when the
// connection has more capacity.
self.pending_capacity.push(stream);
}
if stream.send_flow.available() < stream.requested_send_capacity
&& stream.send_flow.has_unavailable()
{
// The stream requires additional capacity and the stream's
// window has available capacity, but the connection window
// does not.
//
// In this case, the stream needs to be queued up for when the
// connection has more capacity.
self.pending_capacity.push(stream);
}
// If data is buffered and the stream is not pending open, then
@@ -515,26 +509,26 @@ impl Prioritize {
if let Frame::Data(ref frame) = frame {
self.in_flight_data_frame = InFlightData::DataFrame(frame.payload().stream);
}
dst.buffer(frame).ok().expect("invalid frame");
dst.buffer(frame).expect("invalid frame");
// Ensure the codec is ready to try the loop again.
ready!(dst.poll_ready(cx))?;
// Because, always try to reclaim...
self.reclaim_frame(buffer, store, dst);
},
}
None => {
// Try to flush the codec.
ready!(dst.flush(cx))?;
// This might release a data frame...
if !self.reclaim_frame(buffer, store, dst) {
return Poll::Ready(Ok(()))
return Poll::Ready(Ok(()));
}
// No need to poll ready as poll_complete() does this for
// us...
},
}
}
}
}
@@ -603,11 +597,12 @@ impl Prioritize {
/// Push the frame to the front of the stream's deque, scheduling the
/// stream if needed.
fn push_back_frame<B>(&mut self,
frame: Frame<B>,
buffer: &mut Buffer<Frame<B>>,
stream: &mut store::Ptr)
{
fn push_back_frame<B>(
&mut self,
frame: Frame<B>,
buffer: &mut Buffer<Frame<B>>,
stream: &mut store::Ptr,
) {
// Push the frame to the front of the stream's deque
stream.pending_send.push_front(buffer, frame);
@@ -665,8 +660,11 @@ impl Prioritize {
loop {
match self.pending_send.pop(store) {
Some(mut stream) => {
log::trace!("pop_frame; stream={:?}; stream.state={:?}",
stream.id, stream.state);
log::trace!(
"pop_frame; stream={:?}; stream.state={:?}",
stream.id,
stream.state
);
// It's possible that this stream, besides having data to send,
// is also queued to send a reset, and thus is already in the queue
@@ -675,8 +673,11 @@ impl Prioritize {
// To be safe, we just always ask the stream.
let is_pending_reset = stream.is_pending_reset_expiration();
log::trace!(" --> stream={:?}; is_pending_reset={:?};",
stream.id, is_pending_reset);
log::trace!(
" --> stream={:?}; is_pending_reset={:?};",
stream.id,
is_pending_reset
);
let frame = match stream.pending_send.pop_front(buffer) {
Some(Frame::Data(mut frame)) => {
@@ -715,9 +716,7 @@ impl Prioritize {
// happen if the remote reduced the stream
// window. In this case, we need to buffer the
// frame and wait for a window update...
stream
.pending_send
.push_front(buffer, frame.into());
stream.pending_send.push_front(buffer, frame.into());
continue;
}
@@ -726,7 +725,8 @@ impl Prioritize {
let len = cmp::min(sz, max_len);
// Only send up to the stream's window capacity
let len = cmp::min(len, stream_capacity.as_size() as usize) as WindowSize;
let len =
cmp::min(len, stream_capacity.as_size() as usize) as WindowSize;
// There *must* be be enough connection level
// capacity at this point.
@@ -761,20 +761,18 @@ impl Prioritize {
frame.set_end_stream(false);
}
Frame::Data(frame.map(|buf| {
Prioritized {
inner: buf.take(len),
end_of_stream: eos,
stream: stream.key(),
}
Frame::Data(frame.map(|buf| Prioritized {
inner: buf.take(len),
end_of_stream: eos,
stream: stream.key(),
}))
},
Some(frame) => frame.map(|_|
}
Some(frame) => frame.map(|_| {
unreachable!(
"Frame::map closure will only be called \
on DATA frames."
)
),
)
}),
None => {
if let Some(reason) = stream.state.get_scheduled_reset() {
stream.state.set_reset(reason);
@@ -814,7 +812,7 @@ impl Prioritize {
counts.transition_after(stream, is_pending_reset);
return Some(frame);
},
}
None => return None,
}
}