Skip to content

Commit b1ed765

Browse files
committed
chore(quic): simplify check_0rtt
1 parent 77f1e23 commit b1ed765

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

compio-quic/src/connection.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ impl ConnectionState {
8686
.map(|data| data.downcast::<HandshakeData>().unwrap())
8787
}
8888

89-
pub(crate) fn check_0rtt(&self) -> Result<(), ()> {
90-
if self.conn.side().is_server() || self.conn.is_handshaking() || self.conn.accepted_0rtt() {
91-
Ok(())
92-
} else {
93-
Err(())
94-
}
89+
pub(crate) fn check_0rtt(&self) -> bool {
90+
self.conn.side().is_server() || self.conn.is_handshaking() || self.conn.accepted_0rtt()
9591
}
9692
}
9793

compio-quic/src/recv_stream.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl RecvStream {
9191
/// `ClosedStream` errors.
9292
pub fn stop(&mut self, error_code: VarInt) -> Result<(), ClosedStream> {
9393
let mut state = self.conn.state();
94-
if self.is_0rtt && state.check_0rtt().is_err() {
94+
if self.is_0rtt && !state.check_0rtt() {
9595
return Ok(());
9696
}
9797
state.conn.recv_stream(self.stream).stop(error_code)?;
@@ -115,7 +115,7 @@ impl RecvStream {
115115
poll_fn(|cx| {
116116
let mut state = self.conn.state();
117117

118-
if self.is_0rtt && state.check_0rtt().is_err() {
118+
if self.is_0rtt && !state.check_0rtt() {
119119
return Poll::Ready(Err(StoppedError::ZeroRttRejected));
120120
}
121121
if let Some(code) = self.reset {
@@ -169,10 +169,8 @@ impl RecvStream {
169169
}
170170

171171
let mut state = self.conn.state();
172-
if self.is_0rtt {
173-
state
174-
.check_0rtt()
175-
.map_err(|()| ReadError::ZeroRttRejected)?;
172+
if self.is_0rtt && !state.check_0rtt() {
173+
return Poll::Ready(Err(ReadError::ZeroRttRejected));
176174
}
177175

178176
// If we stored an error during a previous call, return it now. This can happen
@@ -395,7 +393,7 @@ impl Drop for RecvStream {
395393
// clean up any previously registered wakers
396394
state.readable.remove(&self.stream);
397395

398-
if state.error.is_some() || (self.is_0rtt && state.check_0rtt().is_err()) {
396+
if state.error.is_some() || (self.is_0rtt && !state.check_0rtt()) {
399397
return;
400398
}
401399
if !self.all_data_read {

compio-quic/src/send_stream.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl SendStream {
9494
/// stream's state.
9595
pub fn reset(&mut self, error_code: VarInt) -> Result<(), ClosedStream> {
9696
let mut state = self.conn.state();
97-
if self.is_0rtt && state.check_0rtt().is_err() {
97+
if self.is_0rtt && !state.check_0rtt() {
9898
return Ok(());
9999
}
100100
state.conn.send_stream(self.stream).reset(error_code)?;
@@ -139,10 +139,8 @@ impl SendStream {
139139
pub async fn stopped(&mut self) -> Result<Option<VarInt>, StoppedError> {
140140
poll_fn(|cx| {
141141
let mut state = self.conn.state();
142-
if self.is_0rtt {
143-
state
144-
.check_0rtt()
145-
.map_err(|()| StoppedError::ZeroRttRejected)?;
142+
if self.is_0rtt && !state.check_0rtt() {
143+
return Poll::Ready(Err(StoppedError::ZeroRttRejected));
146144
}
147145
match state.conn.send_stream(self.stream).stopped() {
148146
Err(_) => Poll::Ready(Ok(None)),
@@ -164,10 +162,8 @@ impl SendStream {
164162
F: FnOnce(quinn_proto::SendStream) -> Result<R, quinn_proto::WriteError>,
165163
{
166164
let mut state = self.conn.try_state()?;
167-
if self.is_0rtt {
168-
state
169-
.check_0rtt()
170-
.map_err(|()| WriteError::ZeroRttRejected)?;
165+
if self.is_0rtt && !state.check_0rtt() {
166+
return Poll::Ready(Err(WriteError::ZeroRttRejected));
171167
}
172168
match f(state.conn.send_stream(self.stream)) {
173169
Ok(r) => {
@@ -252,7 +248,7 @@ impl Drop for SendStream {
252248
state.stopped.remove(&self.stream);
253249
state.writable.remove(&self.stream);
254250

255-
if state.error.is_some() || (self.is_0rtt && state.check_0rtt().is_err()) {
251+
if state.error.is_some() || (self.is_0rtt && !state.check_0rtt()) {
256252
return;
257253
}
258254
match state.conn.send_stream(self.stream).finish() {

0 commit comments

Comments
 (0)