@@ -27,7 +27,6 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>
27
27
28
28
const USB_ACCESSORY_PATH : & str = "/dev/usb_accessory" ;
29
29
const BUFFER_LEN : usize = 16 * 1024 ;
30
- const READ_TIMEOUT : Duration = Duration :: new ( 5 , 0 ) ;
31
30
const TCP_CLIENT_TIMEOUT : Duration = Duration :: new ( 30 , 0 ) ;
32
31
33
32
// tokio_uring::fs::File and tokio_uring::net::TcpStream are using different
@@ -69,6 +68,7 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
69
68
dbg_name_from : & ' static str ,
70
69
dbg_name_to : & ' static str ,
71
70
bytes_written : Arc < AtomicUsize > ,
71
+ read_timeout : Duration ,
72
72
) -> Result < ( ) > {
73
73
let mut buf = vec ! [ 0u8 ; BUFFER_LEN ] ;
74
74
loop {
@@ -77,7 +77,7 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
77
77
// which `Vec<u8>` implements!
78
78
debug ! ( "{}: before read" , dbg_name_from) ;
79
79
let retval = from. read ( buf) ;
80
- let ( res, buf_read) = timeout ( READ_TIMEOUT , retval)
80
+ let ( res, buf_read) = timeout ( read_timeout , retval)
81
81
. await
82
82
. map_err ( |e| -> String { format ! ( "{} read: {}" , dbg_name_from, e) } ) ?;
83
83
// Propagate errors, see how many bytes we read
@@ -93,7 +93,7 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
93
93
// into the full `Vec<u8>`
94
94
debug ! ( "{}: before write" , dbg_name_to) ;
95
95
let retval = to. write ( buf_read. slice ( ..n) ) . submit ( ) ;
96
- let ( res, buf_write) = timeout ( READ_TIMEOUT , retval)
96
+ let ( res, buf_write) = timeout ( read_timeout , retval)
97
97
. await
98
98
. map_err ( |e| -> String { format ! ( "{} write: {}" , dbg_name_to, e) } ) ?;
99
99
let n = res?;
@@ -112,6 +112,7 @@ async fn transfer_monitor(
112
112
stats_interval : Option < Duration > ,
113
113
usb_bytes_written : Arc < AtomicUsize > ,
114
114
tcp_bytes_written : Arc < AtomicUsize > ,
115
+ read_timeout : Duration ,
115
116
) -> Result < ( ) > {
116
117
let mut usb_bytes_out_last: usize = 0 ;
117
118
let mut tcp_bytes_out_last: usize = 0 ;
@@ -163,7 +164,7 @@ async fn transfer_monitor(
163
164
}
164
165
165
166
// transfer stall detection
166
- if stall_check. elapsed ( ) > READ_TIMEOUT {
167
+ if stall_check. elapsed ( ) > read_timeout {
167
168
// compute delta since last check
168
169
stall_usb_bytes_last = usb_bytes_out - stall_usb_bytes_last;
169
170
stall_tcp_bytes_last = tcp_bytes_out - stall_tcp_bytes_last;
@@ -194,6 +195,7 @@ pub async fn io_loop(
194
195
stats_interval : Option < Duration > ,
195
196
need_restart : Arc < Notify > ,
196
197
tcp_start : Arc < Notify > ,
198
+ read_timeout : Duration ,
197
199
) -> Result < ( ) > {
198
200
info ! ( "{} 🛰️ Starting TCP server..." , NAME ) ;
199
201
let bind_addr = format ! ( "0.0.0.0:{}" , TCP_SERVER_PORT ) . parse ( ) . unwrap ( ) ;
@@ -256,17 +258,24 @@ pub async fn io_loop(
256
258
"USB" ,
257
259
"TCP" ,
258
260
stream_bytes. clone ( ) ,
261
+ read_timeout,
259
262
) ) ;
260
263
let mut from_stream = tokio_uring:: spawn ( copy (
261
264
stream. clone ( ) ,
262
265
file. clone ( ) ,
263
266
"TCP" ,
264
267
"USB" ,
265
268
file_bytes. clone ( ) ,
269
+ read_timeout,
266
270
) ) ;
267
271
268
272
// Thread for monitoring transfer
269
- let mut monitor = tokio:: spawn ( transfer_monitor ( stats_interval, file_bytes, stream_bytes) ) ;
273
+ let mut monitor = tokio:: spawn ( transfer_monitor (
274
+ stats_interval,
275
+ file_bytes,
276
+ stream_bytes,
277
+ read_timeout,
278
+ ) ) ;
270
279
271
280
// Stop as soon as one of them errors
272
281
let res = tokio:: try_join!(
0 commit comments