Skip to content

Commit 8f72621

Browse files
authored
Change web-transport-trait::Session::closed() to return a Result (#110)
1 parent 38c2dc2 commit 8f72621

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

web-transport-quinn/src/session.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,11 @@ impl web_transport_trait::Session for Session {
558558
Self::close(self, code, reason.as_bytes());
559559
}
560560

561-
async fn closed(&self) -> Self::Error {
562-
Self::closed(self).await
561+
async fn closed(&self) -> Result<(), Self::Error> {
562+
match Self::closed(self).await {
563+
SessionError::ConnectionError(quinn::ConnectionError::LocallyClosed) => Ok(()),
564+
err => Err(err),
565+
}
563566
}
564567

565568
fn send_datagram(&self, data: Bytes) -> Result<(), Self::Error> {

web-transport-trait/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub trait Session: Clone + MaybeSend + MaybeSync + 'static {
6060
fn close(&self, code: u32, reason: &str);
6161

6262
/// Block until the connection is closed.
63-
fn closed(&self) -> impl Future<Output = Self::Error> + MaybeSend;
63+
fn closed(&self) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
6464
}
6565

6666
/// An outgoing stream of bytes to the peer.

web-transport-wasm/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl web_transport_trait::Session for Session {
162162
Self::close(self, code, reason);
163163
}
164164

165-
async fn closed(&self) -> Self::Error {
166-
Self::closed(self).await
165+
async fn closed(&self) -> Result<(), Self::Error> {
166+
self.closed_inner().await
167167
}
168168

169169
fn send_datagram(&self, _data: Bytes) -> Result<(), Self::Error> {

web-transport-ws/examples/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ async fn run(stream: tokio::net::TcpStream) -> anyhow::Result<()> {
6565

6666
println!("Bidirectional stream closed");
6767
}
68-
err = session.closed() => return Err(err.into()),
68+
result = session.closed() => {
69+
return result.map_err(|e| e.into());
70+
}
6971
}
7072
}
7173
}

web-transport-ws/src/session.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,15 @@ impl generic::Session for Session {
458458
.ok();
459459
}
460460

461-
async fn closed(&self) -> Self::Error {
461+
async fn closed(&self) -> Result<(), Self::Error> {
462462
let mut closed = self.closed.subscribe();
463-
closed
463+
let err = closed
464464
.wait_for(|err| err.is_some())
465465
.await
466466
.map(|e| e.clone().unwrap_or(Error::Closed))
467-
.unwrap_or(Error::Closed)
467+
.unwrap_or(Error::Closed);
468+
469+
Err(err)
468470
}
469471

470472
fn send_datagram(&self, _payload: Bytes) -> Result<(), Self::Error> {

0 commit comments

Comments
 (0)