@@ -13,6 +13,8 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
1313/// An abstract `iroh::endpoint::SendStream`.
1414pub 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
7078impl 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