@@ -13,6 +13,8 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
13
13
/// An abstract `iroh::endpoint::SendStream`.
14
14
pub trait SendStream : Send {
15
15
/// 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.
16
18
fn send_bytes ( & mut self , bytes : Bytes ) -> impl Future < Output = io:: Result < ( ) > > + Send ;
17
19
/// Send that sends a fixed sized buffer.
18
20
fn send < const L : usize > (
@@ -25,6 +27,8 @@ pub trait SendStream: Send {
25
27
fn reset ( & mut self , code : VarInt ) -> io:: Result < ( ) > ;
26
28
/// Wait for the stream to be stopped, returning the error code if it was.
27
29
fn stopped ( & mut self ) -> impl Future < Output = io:: Result < Option < VarInt > > > + Send ;
30
+ /// Get the stream id.
31
+ fn id ( & self ) -> u64 ;
28
32
}
29
33
30
34
/// An abstract `iroh::endpoint::RecvStream`.
@@ -65,6 +69,10 @@ impl SendStream for iroh::endpoint::SendStream {
65
69
async fn stopped ( & mut self ) -> io:: Result < Option < VarInt > > {
66
70
Ok ( self . stopped ( ) . await ?)
67
71
}
72
+
73
+ fn id ( & self ) -> u64 {
74
+ self . id ( ) . index ( )
75
+ }
68
76
}
69
77
70
78
impl RecvStream for iroh:: endpoint:: RecvStream {
@@ -153,6 +161,10 @@ impl<W: SendStream> SendStream for &mut W {
153
161
async fn stopped ( & mut self ) -> io:: Result < Option < VarInt > > {
154
162
self . deref_mut ( ) . stopped ( ) . await
155
163
}
164
+
165
+ fn id ( & self ) -> u64 {
166
+ self . deref ( ) . id ( )
167
+ }
156
168
}
157
169
158
170
#[ derive( Debug ) ]
@@ -289,6 +301,10 @@ impl<W: SendStreamSpecific> SendStream for AsyncWriteSendStream<W> {
289
301
let res = self . 0 . stopped ( ) . await ?;
290
302
Ok ( res)
291
303
}
304
+
305
+ fn id ( & self ) -> u64 {
306
+ 0
307
+ }
292
308
}
293
309
294
310
#[ derive( Debug ) ]
0 commit comments