@@ -6,6 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
6
6
use std:: sync:: Arc ;
7
7
use std:: time:: { Duration , Instant } ;
8
8
use tokio:: sync:: Notify ;
9
+ use tokio:: task:: JoinHandle ;
9
10
use tokio:: time:: { sleep, timeout} ;
10
11
use tokio_uring:: buf:: BoundedBuf ;
11
12
use tokio_uring:: buf:: BoundedBufMut ;
@@ -175,6 +176,14 @@ async fn transfer_monitor(
175
176
}
176
177
}
177
178
179
+ async fn flatten < T > ( handle : & mut JoinHandle < Result < T > > ) -> Result < T > {
180
+ match handle. await {
181
+ Ok ( Ok ( result) ) => Ok ( result) ,
182
+ Ok ( Err ( err) ) => Err ( err) ,
183
+ Err ( _) => Err ( "handling failed" . into ( ) ) ,
184
+ }
185
+ }
186
+
178
187
pub async fn io_loop (
179
188
stats_interval : Option < Duration > ,
180
189
need_restart : Arc < Notify > ,
@@ -251,7 +260,11 @@ pub async fn io_loop(
251
260
let mut monitor = tokio:: spawn ( transfer_monitor ( stats_interval, file_bytes, stream_bytes) ) ;
252
261
253
262
// Stop as soon as one of them errors
254
- let res = tokio:: try_join!( & mut from_file, & mut from_stream, & mut monitor) ;
263
+ let res = tokio:: try_join!(
264
+ flatten( & mut from_file) ,
265
+ flatten( & mut from_stream) ,
266
+ flatten( & mut monitor)
267
+ ) ;
255
268
if let Err ( e) = res {
256
269
error ! ( "{} Connection error: {}" , NAME , e) ;
257
270
}
0 commit comments