@@ -19,6 +19,10 @@ use tokio_uring::UnsubmittedWrite;
19
19
// module name for logging engine
20
20
const NAME : & str = "<i><bright-black> proxy: </>" ;
21
21
22
+ // Just a generic Result type to ease error handling for us. Errors in multithreaded
23
+ // async contexts needs some extra restrictions
24
+ type Result < T > = std:: result:: Result < T , Box < dyn std:: error:: Error + Send + Sync > > ;
25
+
22
26
const USB_ACCESSORY_PATH : & str = "/dev/usb_accessory" ;
23
27
const BUFFER_LEN : usize = 16 * 1024 ;
24
28
const READ_TIMEOUT : Duration = Duration :: new ( 5 , 0 ) ;
@@ -62,7 +66,7 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
62
66
to : Rc < B > ,
63
67
dbg_name : & ' static str ,
64
68
bytes_written : Arc < AtomicUsize > ,
65
- ) -> Result < ( ) , std :: io :: Error > {
69
+ ) -> Result < ( ) > {
66
70
let mut buf = vec ! [ 0u8 ; BUFFER_LEN ] ;
67
71
loop {
68
72
// things look weird: we pass ownership of the buffer to `read`, and we get
@@ -100,7 +104,7 @@ async fn transfer_monitor(
100
104
stats_interval : Option < Duration > ,
101
105
usb_bytes_written : Arc < AtomicUsize > ,
102
106
tcp_bytes_written : Arc < AtomicUsize > ,
103
- ) -> Result < ( ) , std :: io :: Error > {
107
+ ) -> Result < ( ) > {
104
108
let mut usb_bytes_out_last: usize = 0 ;
105
109
let mut tcp_bytes_out_last: usize = 0 ;
106
110
let mut report_time = Instant :: now ( ) ;
@@ -155,7 +159,7 @@ pub async fn io_loop(
155
159
stats_interval : Option < Duration > ,
156
160
need_restart : Arc < Notify > ,
157
161
tcp_start : Arc < Notify > ,
158
- ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
162
+ ) -> Result < ( ) > {
159
163
info ! ( "{} 🛰️ Starting TCP server..." , NAME ) ;
160
164
let bind_addr = format ! ( "0.0.0.0:{}" , TCP_SERVER_PORT ) . parse ( ) . unwrap ( ) ;
161
165
let listener = TcpListener :: bind ( bind_addr) . unwrap ( ) ;
0 commit comments