diff --git a/benches/netbench/src/rust-tcp-bw/client.rs b/benches/netbench/src/rust-tcp-bw/client.rs index 26bf2817c..45d7fbb79 100644 --- a/benches/netbench/src/rust-tcp-bw/client.rs +++ b/benches/netbench/src/rust-tcp-bw/client.rs @@ -7,7 +7,7 @@ extern crate rust_tcp_io_perf; use rust_tcp_io_perf::config; use rust_tcp_io_perf::connection; -use std::io::Write; +use std::io::{self, Write}; fn main() { let args = config::parse_config(); @@ -24,9 +24,15 @@ fn main() { let buf = vec![0; n_bytes]; for _i in 0..n_rounds { - match stream.write_all(&buf) { - Ok(_) => {} - Err(err) => panic!("crazy stuff happened while sending {}", err), + let mut pos = 0; + + while pos < buf.len() { + let bytes_written = match stream.write(&buf[pos..]) { + Ok(len) => len, + Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => 0, + Err(e) => panic!("encountered IO error: {}", e), + }; + pos += bytes_written; } } stream.flush().expect("Unexpected behaviour"); diff --git a/hermit-sys/src/net/device.rs b/hermit-sys/src/net/device.rs index ae71b0387..b6e954519 100644 --- a/hermit-sys/src/net/device.rs +++ b/hermit-sys/src/net/device.rs @@ -20,8 +20,8 @@ extern "Rust" { fn sys_get_mtu() -> Result; fn sys_get_tx_buffer(len: usize) -> Result<(*mut u8, usize), ()>; fn sys_send_tx_buffer(handle: usize, len: usize) -> Result<(), ()>; - fn sys_receive_rx_buffer() -> Result<&'static mut [u8], ()>; - fn sys_rx_buffer_consumed() -> Result<(), ()>; + fn sys_receive_rx_buffer() -> Result<(&'static mut [u8], usize), ()>; + fn sys_rx_buffer_consumed(handle: usize) -> Result<(), ()>; fn sys_free_tx_buffer(handle: usize); } @@ -123,7 +123,7 @@ impl<'a> Device<'a> for HermitNet { fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { match unsafe { sys_receive_rx_buffer() } { - Ok(buffer) => Some((RxToken::new(buffer), TxToken::new())), + Ok((buffer, handle)) => Some((RxToken::new(buffer, handle), TxToken::new())), _ => None, } } @@ -137,11 +137,12 @@ impl<'a> Device<'a> for HermitNet { #[doc(hidden)] pub struct RxToken { buffer: &'static mut [u8], + handle: usize, } impl RxToken { - pub fn new(buffer: &'static mut [u8]) -> Self { - Self { buffer } + pub fn new(buffer: &'static mut [u8], handle: usize) -> Self { + Self { buffer, handle } } } @@ -152,7 +153,7 @@ impl phy::RxToken for RxToken { F: FnOnce(&mut [u8]) -> smoltcp::Result, { let result = f(self.buffer); - if unsafe { sys_rx_buffer_consumed().is_ok() } { + if unsafe { sys_rx_buffer_consumed(self.handle).is_ok() } { result } else { Err(smoltcp::Error::Exhausted) diff --git a/libhermit-rs b/libhermit-rs index f5d1de1f9..fe9dd8be0 160000 --- a/libhermit-rs +++ b/libhermit-rs @@ -1 +1 @@ -Subproject commit f5d1de1f9a3cd2811cce53044b6b6639e7c76039 +Subproject commit fe9dd8be09b8e9961024252b370122b33b4e273c