瀏覽代碼

Merge #588

588: Propagate phy::RawSocket send error to caller r=Dirbaio a=witchof0x20

For #587

Co-authored-by: Jade <jade@witchof.space>
bors[bot] 3 年之前
父節點
當前提交
cb9b4678d7
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 5 2
      src/phy/raw_socket.rs
  2. 1 1
      src/phy/sys/raw_socket.rs

+ 5 - 2
src/phy/raw_socket.rs

@@ -111,7 +111,10 @@ impl phy::TxToken for TxToken {
         let mut lower = self.lower.borrow_mut();
         let mut buffer = vec![0; len];
         let result = f(&mut buffer);
-        lower.send(&buffer[..]).unwrap();
-        result
+        match lower.send(&buffer[..]) {
+            Ok(_) => result,
+            Err(err) if err.kind() == io::ErrorKind::WouldBlock => Err(crate::Error::Exhausted),
+            Err(err) => panic!("{}", err),
+        }
     }
 }

+ 1 - 1
src/phy/sys/raw_socket.rs

@@ -104,7 +104,7 @@ impl RawSocketDesc {
                 0,
             );
             if len == -1 {
-                Err(io::Error::last_os_error()).unwrap()
+                return Err(io::Error::last_os_error());
             }
             Ok(len as usize)
         }