Skip to content

Commit 5e7ff5a

Browse files
authored
Add io-uring-bufring (#46)
* Misc updates for runtime use * Add io-uring-bufring
1 parent d03a2f5 commit 5e7ff5a

File tree

13 files changed

+609
-38
lines changed

13 files changed

+609
-38
lines changed

Cargo.lock

Lines changed: 46 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
2-
members = ["io-uring-bearer", "io-uring-epoll", "io-uring-opcode", "io-uring-fd", "io-uring-owner", "ops/*"]
2+
members = ["io-uring-bearer", "io-uring-epoll", "io-uring-opcode", "io-uring-fd", "io-uring-owner", "io-uring-bufring", "ops/*"]
33
exclude = ["examples/*"]
44
resolver = "2"

io-uring-bearer/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ impl From<OpError> for UringBearerError {
111111
}
112112
}
113113

114-
impl std::error::Error for UringBearerError {}
114+
impl core::error::Error for UringBearerError {}

io-uring-bearer/src/uring.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,17 @@ impl<C: core::fmt::Debug + Clone + OpCompletion> UringBearer<C> {
250250
}
251251
// TODO: Rework - this should be generic and FdKind'ed
252252
#[inline]
253-
fn _fixed_fd_validate(&self, try_fixed_fd: u32) -> bool {
253+
fn _fixed_fd_validate(&self, _try_fixed_fd: u32) -> bool {
254254
// TODO: provide external entity (yaoi) better API to set things registered
255255
return true;
256-
if try_fixed_fd > self.fd_register.capacity() - 1 {
256+
/*
257+
if _try_fixed_fd > self.fd_register.capacity() - 1 {
257258
return false;
258259
}
259-
match self.fd_register.get(try_fixed_fd) {
260+
match self.fd_register.get(_try_fixed_fd) {
260261
Some((_, _itm)) => true,
261262
_ => false,
262-
}
263+
}
264+
*/
263265
}
264266
}

io-uring-bufring/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "io-uring-bufring"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "io_uring bufring"
6+
homepage = "https://github.com/yaws-rs/io_uring-utils"
7+
keywords = ["io", "uring", "epoll", "async"]
8+
license = "Apache-2.0/MIT"
9+
readme = "README.md"
10+
repository = "https://github.com/yaws-rs/io_uring-utils"
11+
categories = ["science"]
12+
13+
[dependencies]
14+
io-uring = { version = "0.7", default-features = false }
15+
io-uring-bearer = { path = "../io-uring-bearer", version = "0.2.0-pre3", default-features = false, optional = true }
16+
io-uring-opcode = { path = "../io-uring-opcode", version = "0.2.0-pre3", default-features = false, optional = true }
17+
anonymous-mmap = { path = "../../ylibc/anonymous_mmap", version = "0.1.0", default-features = false }
18+
libc = { version = "0.2", features = ["extra_traits"] }
19+
20+
[dev-dependencies]
21+
capacity = "0.1"
22+
io-uring-opcode = { path = "../io-uring-opcode", version = "0.2.0-pre3", features = ["accept_multi", "connect", "socket"] }
23+
io-uring-opcode-sets = { path = "../io-uring-opcode-sets", version = "0.0.1-whatever0", features = ["accept_multi", "connect", "socket"] }
24+
ysockaddr = { version = "0.2.0" }
25+
26+
[features]
27+
default = []
28+
bearer = ["dep:io-uring-bearer", "dep:io-uring-opcode"]
29+
30+
[package.metadata.docs.rs]
31+
features = [""]

io-uring-bufring/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# io-uring-bufring
2+
3+
bufring abstraction that can be used with io-uring-bearer or io-uring directly.

io-uring-bufring/src/error.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! io_uring RingBuf Errors
2+
3+
use core::fmt;
4+
use core::fmt::Display;
5+
6+
use anonymous_mmap::AnonymousMmapError;
7+
8+
/// Errors from the UringRingBuf
9+
#[derive(Debug)]
10+
pub enum RingBufError {
11+
/// Given / assumed page size must be divisible with the given buffer size
12+
PageSizeUndivisible,
13+
/// Error during Mmap from AnonymousMmap
14+
Mmap(AnonymousMmapError),
15+
/// io-uring-bearer Related Unregister error
16+
#[cfg(feature = "bearer")]
17+
Unregister(crate::RingBufRegistered, std::io::Error),
18+
/// io-uring-bearer Related Register error
19+
#[cfg(feature = "bearer")]
20+
Register(crate::RingBufUnregistered, std::io::Error),
21+
}
22+
23+
impl Display for RingBufError {
24+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25+
match self {
26+
Self::PageSizeUndivisible => write!(f, "Given / assumed page size must be divisible with the given buffer size"),
27+
Self::Mmap(am) => write!(f, "mmap error: {}", am),
28+
#[cfg(feature = "bearer")]
29+
Self::Register(_, iou) => write!(f, "IoUring Register: {}", iou),
30+
#[cfg(feature = "bearer")]
31+
Self::Unregister(_, iou) => write!(f, "IoUring Unregister: {}", iou),
32+
}
33+
}
34+
}
35+
36+
impl core::error::Error for RingBufError {}

io-uring-bufring/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![warn(
2+
clippy::unwrap_used,
3+
missing_docs,
4+
rust_2018_idioms,
5+
unused_lifetimes,
6+
unused_qualifications
7+
)]
8+
#![doc = include_str!("../README.md")]
9+
10+
//***********************************************
11+
// Re-Exports
12+
//***********************************************
13+
pub use io_uring;
14+
15+
//-----------------------------------------------
16+
// All Errors
17+
//-----------------------------------------------
18+
mod error;
19+
#[doc(inline)]
20+
pub use error::RingBufError;
21+
22+
//-----------------------------------------------
23+
// RingBuf type
24+
//-----------------------------------------------
25+
26+
mod ring_buf;
27+
#[doc(inline)]
28+
pub use ring_buf::*;

0 commit comments

Comments
 (0)