Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR #112 requires a socket handle to consume the buffer #99

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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