Skip to content

Commit

Permalink
Overhaul of buffer representation
Browse files Browse the repository at this point in the history
  • Loading branch information
ileixe committed Oct 10, 2024
1 parent 7587d25 commit e1a5c80
Show file tree
Hide file tree
Showing 29 changed files with 471 additions and 938 deletions.
4 changes: 2 additions & 2 deletions examples/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
tokio_uring::start(async {
// Open the file without blocking
let file = File::open(path).await.unwrap();
let mut buf = vec![0; 16 * 1_024];
let mut buf = vec![0; 16 * 1_024].into();

// Track the current position in the file;
let mut pos = 0;
Expand All @@ -34,7 +34,7 @@ fn main() {
break;
}

out.write_all(&b[..n]).unwrap();
out.write_all(&b[0][..n]).unwrap();
pos += n as u64;

buf = b;
Expand Down
9 changes: 2 additions & 7 deletions examples/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ fn main() {
tokio_uring::spawn(async move {
// Open the file without blocking
let file = File::open(path).await.unwrap();
let mut buf = vec![0; 16 * 1_024];
let mut buf = vec![0; 16 * 1_024].into();

// Track the current position in the file;
let mut pos = 0;

loop {
// Read a chunk
<<<<<<< HEAD
let (res, b) = file.read_at(buf, pos).submit().await;
let n = res.unwrap();
=======
let (n, b) = file.read_at(buf, pos).await.unwrap();
>>>>>>> 6b5865f (Refresh: Update Result<T, B> to be Result<(T,B), Error<B>)
let (n, b) = file.read_at(buf, pos).submit().await.unwrap();

if n == 0 {
break;
Expand Down
47 changes: 0 additions & 47 deletions examples/tcp_listener.rs

This file was deleted.

4 changes: 2 additions & 2 deletions examples/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn main() {

tokio_uring::start(async {
let stream = TcpStream::connect(socket_addr).await.unwrap();
let buf = vec![1u8; 128];
let buf = vec![1u8; 128].into();

let (n, buf) = stream.write(buf).submit().await.unwrap();
println!("written: {}", n);

let (read, buf) = stream.read(buf).await.unwrap();
println!("read: {:?}", &buf[..read]);
println!("read: {:?}", &buf[0][..read]);
});
}
4 changes: 2 additions & 2 deletions examples/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ fn main() {
let stream = listener.accept().await.unwrap();
let socket_addr = socket_addr.clone();
tokio_uring::spawn(async move {
let buf = vec![1u8; 128];
let buf = vec![1u8; 128].into();

let (n, buf) = stream.write(buf).submit().await.unwrap();
println!("written to {}: {}", &socket_addr, n);

let (read, buf) = stream.read(buf).await.unwrap();
println!("read from {}: {:?}", &socket_addr, &buf[..read]);
println!("read from {}: {:?}", &socket_addr, &buf[0][..read]);
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn main() {

tokio_uring::start(async {
let stream = UnixStream::connect(socket_addr).await.unwrap();
let buf = vec![1u8; 128];
let buf = vec![1u8; 128].into();

let (n, buf) = stream.write(buf).submit().await.unwrap();
println!("written: {}", n);

let (read, buf) = stream.read(buf).await.unwrap();
println!("read: {:?}", &buf[..read]);
println!("read: {:?}", &buf[0][..read]);
});
}
2 changes: 1 addition & 1 deletion examples/wrk-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> io::Result<()> {
let (stream, _) = listener.accept().await?;

tokio_uring::spawn(async move {
let result = stream.write(RESPONSE).submit().await;
let result = stream.write(RESPONSE.to_vec().into()).submit().await;
if let Err(err) = result {
eprintln!("Client connection failed: {}", err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/buf/fixed/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use std::sync::Arc;
///
/// # Examples
///
/// ```
/// ```no_compile
/// use tokio_uring::buf::fixed::FixedBufPool;
/// use tokio_uring::buf::IoBuf;
/// use std::iter;
Expand Down
Loading

0 comments on commit e1a5c80

Please sign in to comment.