Skip to content

Commit 6ceacfd

Browse files
committed
PR review: added cancellation safety note and id()
1 parent 3dc6d97 commit 6ceacfd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/util/stream.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
1313
/// An abstract `iroh::endpoint::SendStream`.
1414
pub trait SendStream: Send {
1515
/// Send bytes to the stream. This takes a `Bytes` because iroh can directly use them.
16+
///
17+
/// This method is not cancellation safe. Even if this does not resolve, some bytes may have been written when previously polled.
1618
fn send_bytes(&mut self, bytes: Bytes) -> impl Future<Output = io::Result<()>> + Send;
1719
/// Send that sends a fixed sized buffer.
1820
fn send<const L: usize>(
@@ -25,6 +27,8 @@ pub trait SendStream: Send {
2527
fn reset(&mut self, code: VarInt) -> io::Result<()>;
2628
/// Wait for the stream to be stopped, returning the error code if it was.
2729
fn stopped(&mut self) -> impl Future<Output = io::Result<Option<VarInt>>> + Send;
30+
/// Get the stream id.
31+
fn id(&self) -> u64;
2832
}
2933

3034
/// An abstract `iroh::endpoint::RecvStream`.
@@ -65,6 +69,10 @@ impl SendStream for iroh::endpoint::SendStream {
6569
async fn stopped(&mut self) -> io::Result<Option<VarInt>> {
6670
Ok(self.stopped().await?)
6771
}
72+
73+
fn id(&self) -> u64 {
74+
self.id().index()
75+
}
6876
}
6977

7078
impl RecvStream for iroh::endpoint::RecvStream {
@@ -153,6 +161,10 @@ impl<W: SendStream> SendStream for &mut W {
153161
async fn stopped(&mut self) -> io::Result<Option<VarInt>> {
154162
self.deref_mut().stopped().await
155163
}
164+
165+
fn id(&self) -> u64 {
166+
self.deref().id()
167+
}
156168
}
157169

158170
#[derive(Debug)]
@@ -289,6 +301,10 @@ impl<W: SendStreamSpecific> SendStream for AsyncWriteSendStream<W> {
289301
let res = self.0.stopped().await?;
290302
Ok(res)
291303
}
304+
305+
fn id(&self) -> u64 {
306+
0
307+
}
292308
}
293309

294310
#[derive(Debug)]

0 commit comments

Comments
 (0)