split Client into (Client, Connection) (#107)

The Connection type is a `Future` that drives all of the IO of the
client connection.

The Client type is separate, and is used to send requests into the
connection.
This commit is contained in:
Sean McArthur
2017-09-28 16:55:12 -07:00
committed by GitHub
parent 510800ef28
commit f8efb053b9
23 changed files with 489 additions and 262 deletions

View File

@@ -43,20 +43,9 @@ where
self.init_window_sz
}
/// Update state reflecting a new, locally opened stream
///
/// Returns the stream state if successful. `None` if refused
pub fn open(&mut self, counts: &mut Counts<P>) -> Result<StreamId, UserError> {
if !counts.can_inc_num_send_streams() {
return Err(Rejected.into());
}
pub fn open(&mut self) -> Result<StreamId, UserError> {
let stream_id = self.try_open()?;
// Increment the number of locally initiated streams
counts.inc_num_send_streams();
self.next_stream_id = stream_id.next_id();
Ok(stream_id)
}
@@ -64,6 +53,7 @@ where
&mut self,
frame: frame::Headers,
stream: &mut store::Ptr<B, P>,
counts: &mut Counts<P>,
task: &mut Option<Task>,
) -> Result<(), UserError> {
trace!(
@@ -77,6 +67,14 @@ where
// Update the state
stream.state.send_open(end_stream)?;
if P::is_local_init(frame.stream_id()) {
if counts.can_inc_num_send_streams() {
counts.inc_num_send_streams();
} else {
self.prioritize.queue_open(stream);
}
}
// Queue the frame for sending
self.prioritize.queue_frame(frame.into(), stream, task);