Trying to get something working

This commit is contained in:
Carl Lerche
2017-08-10 13:15:40 -07:00
parent 6c962491c6
commit a1b03b7724
7 changed files with 127 additions and 39 deletions

View File

@@ -16,6 +16,10 @@ pub(super) struct Prioritize<B> {
/// Holds frames that are waiting to be written to the socket
buffer: Buffer<B>,
/// Holds the connection task. This signals the connection that there is
/// data to flush.
conn_task: Option<task::Task>,
}
impl<B> Prioritize<B>
@@ -28,6 +32,7 @@ impl<B> Prioritize<B>
flow_control: FlowControl::new(config.init_local_window_sz),
buffered_data: 0,
buffer: Buffer::new(),
conn_task: None,
}
}
@@ -71,6 +76,10 @@ impl<B> Prioritize<B>
// Queue the stream
push_sender(&mut self.pending_send, stream);
if let Some(ref task) = self.conn_task {
task.notify();
}
}
pub fn poll_complete<T>(&mut self,
@@ -79,12 +88,16 @@ impl<B> Prioritize<B>
-> Poll<(), ConnectionError>
where T: AsyncWrite,
{
self.conn_task = Some(task::current());
trace!("poll_complete");
loop {
// Ensure codec is ready
try_ready!(dst.poll_ready());
match self.pop_frame(store) {
Some(frame) => {
trace!("writing frame={:?}", frame);
// Subtract the data size
self.buffered_data -= frame.flow_len();

View File

@@ -79,6 +79,7 @@ impl<B> Send<B> where B: Buf {
stream: &mut store::Ptr<B>)
-> Result<(), ConnectionError>
{
trace!("send_headers; frame={:?}", frame);
// Update the state
stream.state.send_open(self.init_window_sz, frame.is_end_stream())?;
@@ -252,6 +253,26 @@ impl<B> Send<B> where B: Buf {
Ok(())
}
pub fn window_size(&mut self, stream: &mut Stream<B>) -> usize {
if let Some(flow) = stream.state.send_flow_control() {
// Track the current task
stream.send_task = Some(task::current());
// We are observing the window, so apply the pending updates
flow.apply_window_update();
let mut window = flow.effective_window_size();
if stream.unadvertised_send_window > window {
return 0;
}
return (window - stream.unadvertised_send_window) as usize;
}
0
}
pub fn dec_num_streams(&mut self) {
self.num_streams -= 1;
}

View File

@@ -190,40 +190,6 @@ impl<B> Streams<B>
me.actions.recv.recv_push_promise::<P>(frame, &mut stream)
}
pub fn send_headers(&mut self, headers: frame::Headers)
-> Result<(), ConnectionError>
{
unimplemented!();
/*
let id = frame.stream_id();
let mut me = self.inner.lock().unwrap();
let me = &mut *me;
// let (id, state) = me.actions.send.open());
let state = match me.store.entry(id) {
Entry::Occupied(e) => e.into_mut(),
Entry::Vacant(e) => {
let (id, state) = try!(me.actions.send.open());
e.insert(state)
}
};
if frame.is_trailers() {
try!(me.actions.send.send_eos(state));
} else {
try!(me.actions.send.send_headers(state, frame.is_end_stream()));
}
if state.is_closed() {
me.actions.dec_num_streams(id);
}
Ok(())
*/
}
pub fn next_incoming(&mut self) -> Option<StreamRef<B>> {
let key = {
let mut me = self.inner.lock().unwrap();
@@ -399,6 +365,15 @@ impl<B> StreamRef<B>
Ok(chunk.into())
}
/// Returns the current window size
pub fn window_size(&mut self) -> usize {
let mut me = self.inner.lock().unwrap();
let me = &mut *me;
let mut stream = me.store.resolve(self.key);
me.actions.send.window_size(&mut stream)
}
}
impl<B> Clone for StreamRef<B> {