Skip to content

Commit

Permalink
Merge hermit-os#99
Browse files Browse the repository at this point in the history
99: PR hermit-os#112 requires a socket handle to consume the buffer r=stlankes a=stlankes

in addition, we revised the benchmark to measure the stream bandwidth and supports now also non-blocking streams.

Co-authored-by: Stefan Lankes <[email protected]>
  • Loading branch information
bors[bot] and stlankes authored Jan 4, 2021
2 parents 8f890a1 + fe3ddc8 commit 0f0f43b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
14 changes: 10 additions & 4 deletions benches/netbench/src/rust-tcp-bw/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand Down
13 changes: 7 additions & 6 deletions hermit-sys/src/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extern "Rust" {
fn sys_get_mtu() -> Result<u16, ()>;
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);
}

Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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 }
}
}

Expand All @@ -152,7 +153,7 @@ impl phy::RxToken for RxToken {
F: FnOnce(&mut [u8]) -> smoltcp::Result<R>,
{
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)
Expand Down
2 changes: 1 addition & 1 deletion libhermit-rs

0 comments on commit 0f0f43b

Please sign in to comment.