mirror of
https://github.com/n0-computer/noq.git
synced 2026-10-03 12:40:46 +00:00
H3: simplify SendUni state machine
This commit is contained in:
@@ -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()),
|
||||
],
|
||||
})),
|
||||
})
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user