Skip to content

Commit 57e0c3e

Browse files
committed
io_uring: generic Result type
1 parent f88ea94 commit 57e0c3e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/io_uring.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use tokio_uring::UnsubmittedWrite;
1919
// module name for logging engine
2020
const NAME: &str = "<i><bright-black> proxy: </>";
2121

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+
2226
const USB_ACCESSORY_PATH: &str = "/dev/usb_accessory";
2327
const BUFFER_LEN: usize = 16 * 1024;
2428
const READ_TIMEOUT: Duration = Duration::new(5, 0);
@@ -62,7 +66,7 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
6266
to: Rc<B>,
6367
dbg_name: &'static str,
6468
bytes_written: Arc<AtomicUsize>,
65-
) -> Result<(), std::io::Error> {
69+
) -> Result<()> {
6670
let mut buf = vec![0u8; BUFFER_LEN];
6771
loop {
6872
// things look weird: we pass ownership of the buffer to `read`, and we get
@@ -100,7 +104,7 @@ async fn transfer_monitor(
100104
stats_interval: Option<Duration>,
101105
usb_bytes_written: Arc<AtomicUsize>,
102106
tcp_bytes_written: Arc<AtomicUsize>,
103-
) -> Result<(), std::io::Error> {
107+
) -> Result<()> {
104108
let mut usb_bytes_out_last: usize = 0;
105109
let mut tcp_bytes_out_last: usize = 0;
106110
let mut report_time = Instant::now();
@@ -155,7 +159,7 @@ pub async fn io_loop(
155159
stats_interval: Option<Duration>,
156160
need_restart: Arc<Notify>,
157161
tcp_start: Arc<Notify>,
158-
) -> Result<(), Box<dyn std::error::Error>> {
162+
) -> Result<()> {
159163
info!("{} 🛰️ Starting TCP server...", NAME);
160164
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();
161165
let listener = TcpListener::bind(bind_addr).unwrap();

0 commit comments

Comments
 (0)