H3: simplify SendUni state machine

This commit is contained in:
stammw
2019-11-29 16:13:37 +01:00
committed by Dirkjan Ochtman
parent 84e041939d
commit 69a9545632
2 changed files with 6 additions and 10 deletions
+3 -3
View File
@@ -75,9 +75,9 @@ impl ConnectionRef {
recv_decoder: None,
blocked_streams: BTreeMap::new(),
send_unis: [
SendUni::new(StreamType::CONTROL, quic.clone()),
SendUni::new(StreamType::ENCODER, quic.clone()),
SendUni::new(StreamType::DECODER, quic),
SendUni::new(StreamType::CONTROL, quic.open_uni()),
SendUni::new(StreamType::ENCODER, quic.open_uni()),
SendUni::new(StreamType::DECODER, quic.open_uni()),
],
})),
})
+3 -7
View File
@@ -94,17 +94,16 @@ pub struct SendUni {
}
impl SendUni {
pub(super) fn new(ty: StreamType, quic: quinn::Connection) -> Self {
pub(super) fn new(ty: StreamType, open_uni: quinn::OpenUni) -> Self {
Self {
ty,
state: SendUniState::New(quic),
state: SendUniState::Opening(open_uni),
data: VecDeque::with_capacity(2),
}
}
}
enum SendUniState {
New(quinn::Connection),
Opening(OpenUni),
Idle(SendStream),
Sending(SendStream, Bytes),
@@ -124,13 +123,10 @@ impl Future for SendUni {
let is_empty = self.data.is_empty();
loop {
match self.state {
SendUniState::New(ref mut c) => {
SendUniState::Opening(ref mut o) => {
if is_empty {
return Poll::Ready(Ok(()));
}
self.state = SendUniState::Opening(c.open_uni());
}
SendUniState::Opening(ref mut o) => {
let send = ready!(Pin::new(o).poll(cx))?;
self.state = SendUniState::Sending(send, self.ty.encoded());
}