Files
h2/src/proto/settings.rs
Oliver Gould 897bf84163 Use rustfmt to enforce consistent formatting
This change adds a .rustfmt.toml that includes ALL supported settings,
12 of which we have overridden to attempt to cater to our own
proclivities.

rustfmt is checked in the rust-nightly CI job.
2017-09-12 22:29:35 +00:00

71 lines
1.7 KiB
Rust

use codec::RecvError;
use frame;
use proto::*;
#[derive(Debug)]
pub(crate) struct Settings {
/// Received SETTINGS frame pending processing. The ACK must be written to
/// the socket first then the settings applied **before** receiving any
/// further frames.
pending: Option<frame::Settings>,
}
impl Settings {
pub fn new() -> Self {
Settings {
pending: None,
}
}
pub fn recv_settings(&mut self, frame: frame::Settings) {
if frame.is_ack() {
debug!("received remote settings ack");
// TODO: handle acks
} else {
assert!(self.pending.is_none());
self.pending = Some(frame);
}
}
pub fn send_pending_ack<T, B, C, P>(
&mut self,
dst: &mut Codec<T, B>,
streams: &mut Streams<C, P>,
) -> Poll<(), RecvError>
where
T: AsyncWrite,
B: Buf,
C: Buf,
P: Peer,
{
trace!("send_pending_ack; pending={:?}", self.pending);
if let Some(ref settings) = self.pending {
if !dst.poll_ready()?.is_ready() {
trace!("failed to send ACK");
return Ok(Async::NotReady);
}
// Create an ACK settings frame
let frame = frame::Settings::ack();
// Buffer the settings frame
dst.buffer(frame.into())
.ok()
.expect("invalid settings frame");
trace!("ACK sent; applying settings");
if let Some(val) = settings.max_frame_size() {
dst.set_max_send_frame_size(val as usize);
}
streams.apply_remote_settings(settings)?;
}
self.pending = None;
Ok(().into())
}
}