Kaynağa Gözat

Propagate phy::RawSocket send error to caller

Jade 3 yıl önce
ebeveyn
işleme
32bf949dc8
2 değiştirilmiş dosya ile 7 ekleme ve 2 silme
  1. 6 1
      src/phy/raw_socket.rs
  2. 1 1
      src/phy/sys/raw_socket.rs

+ 6 - 1
src/phy/raw_socket.rs

@@ -111,7 +111,12 @@ 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();
+        if let Err(err) = lower.send(&buffer[..]) {
+            return match err.kind() {
+                io::ErrorKind::WouldBlock => Err(crate::Error::Exhausted),
+                _ => Err(crate::Error::Illegal),
+            };
+        }
         result
     }
 }

+ 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)
         }