Skip to content

Commit

Permalink
Change Result types
Browse files Browse the repository at this point in the history
  • Loading branch information
ollie-etl committed Feb 13, 2024
1 parent cb2cab3 commit d84e764
Show file tree
Hide file tree
Showing 29 changed files with 253 additions and 243 deletions.
4 changes: 1 addition & 3 deletions examples/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ fn main() {

loop {
// Read a chunk
let (res, b) = file.read_at(buf, pos).await;
let n = res.unwrap();

let (n, b) = file.read_at(buf, pos).await.unwrap();
if n == 0 {
break;
}
Expand Down
7 changes: 3 additions & 4 deletions examples/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ fn main() {

loop {
// Read a chunk
let (res, b) = file.read_at(buf, pos).await;
let n = res.unwrap();
let (n, b) = file.read_at(buf, pos).await.unwrap();

if n == 0 {
break;
}

let (res, b) = socket.write(b).submit().await;
pos += res.unwrap() as u64;
let (n, b) = socket.write(b).submit().await.unwrap();
pos += n as u64;

buf = b;
}
Expand Down
6 changes: 2 additions & 4 deletions examples/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ fn main() {

let mut buf = vec![0u8; 4096];
loop {
let (result, nbuf) = stream.read(buf).await;
let (read, nbuf) = stream.read(buf).await.unwrap();
buf = nbuf;
let read = result.unwrap();
if read == 0 {
println!("{} closed, {} total ping-ponged", socket_addr, n);
break;
}

let (res, slice) = stream.write_all(buf.slice(..read)).await;
let _ = res.unwrap();
let (_, slice) = stream.write_all(buf.slice(..read)).await.unwrap();
buf = slice.into_inner();
println!("{} all {} bytes ping-ponged", socket_addr, read);
n += read;
Expand Down
7 changes: 2 additions & 5 deletions examples/tcp_listener_fixed_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,14 @@ async fn echo_handler<T: IoBufMut>(
// Each time through the loop, use fbuf and then get it back for the next
// iteration.

let (result, fbuf1) = stream.read_fixed(fbuf).await;
let (read, fbuf1) = stream.read_fixed(fbuf).await.unwrap();
fbuf = {
let read = result.unwrap();
if read == 0 {
break;
}
assert_eq!(4096, fbuf1.len()); // To prove a point.

let (res, nslice) = stream.write_fixed_all(fbuf1.slice(..read)).await;

let _ = res.unwrap();
let (_, nslice) = stream.write_fixed_all(fbuf1.slice(..read)).await.unwrap();
println!("peer {} all {} bytes ping-ponged", peer, read);
n += read;

Expand Down
7 changes: 3 additions & 4 deletions examples/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ fn main() {
let stream = TcpStream::connect(socket_addr).await.unwrap();
let buf = vec![1u8; 128];

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

let (result, buf) = stream.read(buf).await;
let read = result.unwrap();
let (read, buf) = stream.read(buf).await.unwrap();
println!("read: {:?}", &buf[..read]);
});
}
7 changes: 3 additions & 4 deletions examples/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ fn main() {

let buf = vec![0u8; 128];

let (result, mut buf) = socket.recv_from(buf).await;
let (read, socket_addr) = result.unwrap();
let ((read, socket_addr), mut buf) = socket.recv_from(buf).await.unwrap();
buf.resize(read, 0);
println!("received from {}: {:?}", socket_addr, &buf[..]);

let (result, _buf) = socket.send_to(buf, socket_addr).await;
println!("sent to {}: {}", socket_addr, result.unwrap());
let (n, _buf) = socket.send_to(buf, socket_addr).await.unwrap();
println!("sent to {}: {}", socket_addr, n);
});
}
7 changes: 3 additions & 4 deletions examples/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ fn main() {
tokio_uring::spawn(async move {
let buf = vec![1u8; 128];

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

let (result, buf) = stream.read(buf).await;
let read = result.unwrap();
let (read, buf) = stream.read(buf).await.unwrap();
println!("read from {}: {:?}", &socket_addr, &buf[..read]);
});
}
Expand Down
7 changes: 3 additions & 4 deletions examples/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ fn main() {
let stream = UnixStream::connect(socket_addr).await.unwrap();
let buf = vec![1u8; 128];

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

let (result, buf) = stream.read(buf).await;
let read = result.unwrap();
let (read, buf) = stream.read(buf).await.unwrap();
println!("read: {:?}", &buf[..read]);
});
}
3 changes: 1 addition & 2 deletions examples/wrk-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,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).submit().await;
if let Err(err) = result {
eprintln!("Client connection failed: {}", err);
}
Expand Down
Loading

0 comments on commit d84e764

Please sign in to comment.