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

Rewrite internals #142

Draft
wants to merge 284 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
284 commits
Select commit Hold shift + click to select a range
ff9796a
Some todos
Thomasdezeeuw Oct 5, 2024
1d417b6
Implement submissions
Thomasdezeeuw Oct 5, 2024
803c8ee
Implement fmt::Debug for {sq,cq}::Queue
Thomasdezeeuw Oct 5, 2024
392c632
Release operation slot if the queue is full
Thomasdezeeuw Oct 5, 2024
aa34bc9
Implement Debug for more types
Thomasdezeeuw Oct 5, 2024
1ab254a
Remove unused trait bound
Thomasdezeeuw Oct 6, 2024
464bdd6
Move SubmissionQueue above shared state
Thomasdezeeuw Oct 6, 2024
5771698
Add Implementation trait
Thomasdezeeuw Oct 6, 2024
855defc
Add kqueue Implementation (trait) impl
Thomasdezeeuw Oct 6, 2024
49661d9
Use Implementation trait
Thomasdezeeuw Oct 6, 2024
c253f0b
Small cleanup
Thomasdezeeuw Oct 6, 2024
5710add
Make MAX_CHANGE_LIST_SIZE configurable
Thomasdezeeuw Oct 6, 2024
1bb6886
Use Self in builder pattern
Thomasdezeeuw Oct 6, 2024
617dd72
Implement fmt::Debug for kqueue::Event
Thomasdezeeuw Oct 6, 2024
edbf448
Update Config::max_change_list_size docs
Thomasdezeeuw Oct 6, 2024
05a78d3
Change op_index to OperationId
Thomasdezeeuw Oct 6, 2024
52c6bc2
Use OperationId in sq::Queue::add
Thomasdezeeuw Oct 6, 2024
d5c54f6
Add sq::Queue::wait_for_submission
Thomasdezeeuw Oct 6, 2024
ababf34
Add type for cq::Event::State for kqueue
Thomasdezeeuw Oct 6, 2024
d5d01bf
Remove DropWaker for ()
Thomasdezeeuw Oct 12, 2024
3f27b0e
Rename sq::Queue::add to submit
Thomasdezeeuw Oct 13, 2024
113f99e
Improve logging for unhandled completion
Thomasdezeeuw Oct 13, 2024
4eed4d2
Remove Option from QueuedOperation
Thomasdezeeuw Oct 13, 2024
f7bd37f
Rewrite sq::Queue::submit
Thomasdezeeuw Oct 13, 2024
9402de1
Improve logging in kqueue implementation
Thomasdezeeuw Oct 13, 2024
76e3e1d
Add sq::Queue::resubmit
Thomasdezeeuw Oct 13, 2024
46a6ea3
Rename submit to fill in sq::Queue methods
Thomasdezeeuw Oct 13, 2024
a0b4a19
Add Operation Future
Thomasdezeeuw Oct 13, 2024
079be9c
Remove unused code and imports
Thomasdezeeuw Oct 13, 2024
e282209
Add kqueue specific Op trait
Thomasdezeeuw Oct 13, 2024
52b9cb2
Add back AsyncFd::read(_at)
Thomasdezeeuw Oct 13, 2024
b5b3bc9
Implement fmt::Debug for Read
Thomasdezeeuw Oct 13, 2024
25f6072
Implement Future for Read
Thomasdezeeuw Oct 13, 2024
173b45e
Add op_future macro
Thomasdezeeuw Oct 13, 2024
c77f021
Replace Read impl with op_future
Thomasdezeeuw Oct 13, 2024
b8ec72c
Derive Debug for kqueue::Shared
Thomasdezeeuw Oct 13, 2024
4ebd18d
Add back initial io_uring implementation
Thomasdezeeuw Oct 15, 2024
8fa4a6d
Implement Read operation for io_uring
Thomasdezeeuw Oct 15, 2024
24892d5
Don't resubmit for io_uring
Thomasdezeeuw Oct 17, 2024
088a501
Create type alias for operation return result
Thomasdezeeuw Oct 17, 2024
d806a01
Add io_uring specific Op trait
Thomasdezeeuw Oct 17, 2024
26cf1a2
Add back BufMut::{buffer_group,buffer_init}
Thomasdezeeuw Oct 17, 2024
87dc544
Implemeny Send & Sync for op::State
Thomasdezeeuw Oct 19, 2024
df5720b
Implement RefUnwindSafe for State
Thomasdezeeuw Oct 19, 2024
5cf6bfa
Fix doc link in Read docs
Thomasdezeeuw Oct 19, 2024
38a234f
Simplify io_uring::Read::check_result
Thomasdezeeuw Oct 19, 2024
4b816a7
Fix generic error message
Thomasdezeeuw Oct 19, 2024
1023418
Derive Debug for OpResult
Thomasdezeeuw Oct 19, 2024
b09bfe5
Fix setting done for io_uring completion events
Thomasdezeeuw Oct 19, 2024
5551429
Add more trace logging
Thomasdezeeuw Oct 19, 2024
793437d
Add basic testing example
Thomasdezeeuw Oct 19, 2024
4226e9b
Prefix io_uring types with io_uring::
Thomasdezeeuw Oct 19, 2024
cf8f5b4
Make queued operation slot available after usage
Thomasdezeeuw Oct 19, 2024
dd8b95c
Cleanup test example
Thomasdezeeuw Oct 19, 2024
a0b86fc
Add manual links to kqueue module
Thomasdezeeuw Oct 19, 2024
abde014
Move kqueue Submissions to its own file
Thomasdezeeuw Oct 19, 2024
cd61d91
Move kqueue::Completions to its own module
Thomasdezeeuw Oct 19, 2024
de98a2b
Reimplement Drop for AsyncFd
Thomasdezeeuw Nov 3, 2024
8630dd3
Set id for submissions without completion event
Thomasdezeeuw Nov 3, 2024
d3834f9
Change logging for unexpected completion events
Thomasdezeeuw Nov 3, 2024
bc05102
Move more error handling into sq::Queue::submit_with_id
Thomasdezeeuw Nov 3, 2024
b592664
Make sure we wait for a submission slot if none are available
Thomasdezeeuw Nov 3, 2024
04a80b5
Mark sq::Queue::resubmit and submit_with_id as unsafe
Thomasdezeeuw Nov 3, 2024
78f7c1a
Allow multiple futures in op_futures! macro
Thomasdezeeuw Nov 5, 2024
69e2a8e
Update comment
Thomasdezeeuw Nov 5, 2024
2a9548c
Add boolean to OpResult::Again
Thomasdezeeuw Nov 5, 2024
1c128ef
Remove old io_uring code
Thomasdezeeuw Nov 5, 2024
6386a36
Drop drop_by_ptr
Thomasdezeeuw Nov 5, 2024
5d747fb
Set descriptor specific flags
Thomasdezeeuw Nov 5, 2024
c2d2d1b
Add cq::OperationState to support multishot operations
Thomasdezeeuw Nov 5, 2024
ddd25a8
Add sq::Queue::submit_multishot
Thomasdezeeuw Nov 5, 2024
26e6a39
Move unused_macros to debug_detail
Thomasdezeeuw Nov 5, 2024
c9017ab
Remove allow(unused_imports)
Thomasdezeeuw Nov 5, 2024
570d576
Add back Std{in,out,err}
Thomasdezeeuw Nov 6, 2024
06090f8
Move sys::io files to its own directories
Thomasdezeeuw Nov 6, 2024
7736508
Make NO_COMPLETION_ID unique
Thomasdezeeuw Nov 30, 2024
5a77e57
Make is_send_and_sync for Direct Linux only
Thomasdezeeuw Nov 30, 2024
cdc02d3
Add more read tests
Thomasdezeeuw Nov 30, 2024
398e368
Add general public type for Config
Thomasdezeeuw Nov 30, 2024
f65ad4d
Split queued_operations config from submission queue size
Thomasdezeeuw Nov 30, 2024
16a4eba
Remove Unpin requirement from Operation future
Thomasdezeeuw Dec 1, 2024
788b407
Add back AsyncFd::read_n
Thomasdezeeuw Dec 1, 2024
4b55dbf
Add Io(Mut)Slice types
Thomasdezeeuw Dec 1, 2024
7d723b8
Add const generic in op_future!
Thomasdezeeuw Dec 1, 2024
2877652
Enable buffer group assertions
Thomasdezeeuw Dec 1, 2024
3048c01
Port back part of the cancel module
Thomasdezeeuw Dec 15, 2024
57c0306
Add back read_vectored(_at)
Thomasdezeeuw Dec 15, 2024
d563cc5
Don't implement Unpin for ReadVectored
Thomasdezeeuw Dec 15, 2024
83d952f
Move State creation into a new function
Thomasdezeeuw Dec 15, 2024
f5d4176
Add back Extract trait
Thomasdezeeuw Dec 15, 2024
756038a
Export Cancel trait at the root of crate
Thomasdezeeuw Dec 15, 2024
6e3940f
Add back Ring::enable
Thomasdezeeuw Dec 15, 2024
78f6307
Add AsyncFd::try_clone
Thomasdezeeuw Dec 15, 2024
babbed4
Add back AsyncFd::to_direct_descriptor
Thomasdezeeuw Dec 15, 2024
6f429e5
Add back AsyncFd::to_file_descriptor
Thomasdezeeuw Dec 15, 2024
121787d
Remove io_uring::Op::check_result
Thomasdezeeuw Dec 15, 2024
cec7ede
Move sys::io modules
Thomasdezeeuw Dec 15, 2024
914b313
Improve AsyncFd docs
Thomasdezeeuw Dec 15, 2024
c2c1ad4
Improve all_bufs macro
Thomasdezeeuw Dec 15, 2024
1c813d3
Move poll op::State to method
Thomasdezeeuw Dec 15, 2024
0706998
Rename sys::CancelAll to CancelAllOp
Thomasdezeeuw Dec 15, 2024
8bbcb8a
Rename sys::Read to ReadOp
Thomasdezeeuw Dec 15, 2024
37d8c13
Rename sys::ReadVectored to ReadVectoredOp
Thomasdezeeuw Dec 15, 2024
0c0eb65
Prefix Operation and Op with Fd
Thomasdezeeuw Dec 15, 2024
8f5828c
Add skeleton for Operation type
Thomasdezeeuw Dec 15, 2024
726894a
Add Op trait not-fd version of FdOp
Thomasdezeeuw Dec 15, 2024
28e0f92
Add op::State::poll
Thomasdezeeuw Dec 15, 2024
86a35f0
Rename op_future to fd_operation
Thomasdezeeuw Dec 15, 2024
2914f16
Ordering of types in op module
Thomasdezeeuw Dec 15, 2024
79f2681
Add must_use to all fd_operation Futures
Thomasdezeeuw Dec 15, 2024
9b4b960
Add io_uring and kqueue Op traits
Thomasdezeeuw Dec 15, 2024
0dcf94c
Add operation macro
Thomasdezeeuw Dec 15, 2024
43ac3ea
Add back Cancel::cancel
Thomasdezeeuw Dec 15, 2024
644e5f8
Implement Cancel for all FdOperations
Thomasdezeeuw Dec 15, 2024
c19e538
Add FIXME
Thomasdezeeuw Dec 15, 2024
1520acb
Start adding back fs module
Thomasdezeeuw Dec 15, 2024
0149ab9
Add back fs::OpenOptions and fs::Open
Thomasdezeeuw Dec 15, 2024
ab9d6cb
Pass a reference to SubmissionQueue in Op::map_result
Thomasdezeeuw Dec 15, 2024
85a7e96
Add back some more fs types
Thomasdezeeuw Dec 15, 2024
b4eb336
Add more API to QueueFull error
Thomasdezeeuw Dec 27, 2024
523a955
Add back ReadBufPool types
Thomasdezeeuw Dec 27, 2024
9778965
Add mem module back
Thomasdezeeuw Dec 27, 2024
c15218d
Fix and ignore various Clippy lints
Thomasdezeeuw Dec 27, 2024
b5f4713
Rename sys::mem::Advise to AdviseOp
Thomasdezeeuw Dec 27, 2024
e83d78f
Add back AsyncFd::sync_{all,data}
Thomasdezeeuw Dec 27, 2024
0f9ca8c
Add back AsyncFd::metadata
Thomasdezeeuw Dec 27, 2024
030152e
Add back AsyncFd::advise
Thomasdezeeuw Dec 27, 2024
cb37976
Add back AsyncFd::allocate
Thomasdezeeuw Dec 27, 2024
5e1aee1
Add back AsyncFd::truncate
Thomasdezeeuw Dec 27, 2024
0ed389e
Add back fs::create_dir
Thomasdezeeuw Dec 27, 2024
185aa42
Add back fs::rename
Thomasdezeeuw Dec 27, 2024
944ff9a
Add back fs::remove_{file,dir}
Thomasdezeeuw Dec 27, 2024
34c51b5
Match ordering in fs module
Thomasdezeeuw Dec 27, 2024
cc73170
Export fd::{ToDirect, ToFd}
Thomasdezeeuw Dec 27, 2024
c06d404
Fix two doc links
Thomasdezeeuw Dec 27, 2024
d847164
Implement Copy for RemoveFlag and SyncDataFlag
Thomasdezeeuw Dec 27, 2024
88c3c64
Add back AsyncFd::read_n_vectored(_at)
Thomasdezeeuw Dec 27, 2024
56da87e
Add back AsyncFd::write(_at)
Thomasdezeeuw Dec 27, 2024
92791fe
Add FdOpExtract trait
Thomasdezeeuw Dec 27, 2024
8e1c1d1
Implement FdOpExtract for WriteOp
Thomasdezeeuw Dec 27, 2024
656f390
Support implementing Extract in fd_operation!
Thomasdezeeuw Dec 27, 2024
5d799e0
Implement Extract for io::Write
Thomasdezeeuw Dec 27, 2024
5711bc2
Add back AsyncFd::write_all
Thomasdezeeuw Dec 27, 2024
f12c4f7
Support Extract method in operation! macro
Thomasdezeeuw Dec 27, 2024
f3f939d
Implement Extract for fs::CreateDir
Thomasdezeeuw Dec 27, 2024
17cccd2
Implement Extract for fs::Rename
Thomasdezeeuw Dec 27, 2024
272e599
Implement Extract for fs::Delete
Thomasdezeeuw Dec 27, 2024
07e0d72
Implement Extract for fs::Open
Thomasdezeeuw Dec 27, 2024
8369ef7
Remove io_uring::Submission methods
Thomasdezeeuw Dec 27, 2024
71db84a
Add back AsyncFd::write_vectored(_at)
Thomasdezeeuw Dec 27, 2024
6e51a54
Add back AsyncFd::write_all_vectored(_at)
Thomasdezeeuw Dec 27, 2024
7d769dc
Add back AsyncFd::splice*
Thomasdezeeuw Dec 27, 2024
f243983
Add back AsyncFd::close
Thomasdezeeuw Dec 27, 2024
78af9f9
add back process:wait
Thomasdezeeuw Dec 28, 2024
873372d
Add back process::Signals
Thomasdezeeuw Dec 28, 2024
8071eb6
Always intralink Future in (fd_)operation! macro
Thomasdezeeuw Dec 28, 2024
ddf1c7f
Refact op module
Thomasdezeeuw Dec 28, 2024
981abad
Implement Cancel for operation! macro
Thomasdezeeuw Dec 28, 2024
e462cd6
Implement Cancel for various io Futures
Thomasdezeeuw Dec 28, 2024
f6064e4
Merge operation and fd_operation macros
Thomasdezeeuw Dec 28, 2024
ad58b0f
Use UnsafeCell in StatOp
Thomasdezeeuw Dec 28, 2024
e7670a1
Fix and silence various Clippy lints
Thomasdezeeuw Dec 28, 2024
fc573a3
Fix various doc links
Thomasdezeeuw Dec 28, 2024
7502b62
Add sq::Queue::queue(_mulitshot)
Thomasdezeeuw Dec 28, 2024
d111fc8
Use level 1 header for Examples
Thomasdezeeuw Dec 29, 2024
0a60c66
Add back net::socket
Thomasdezeeuw Dec 29, 2024
a7c4a12
Add android cfgs
Thomasdezeeuw Dec 29, 2024
f14bdaf
Add back SocketAddress trait and implementations
Thomasdezeeuw Dec 29, 2024
bd724cf
Rewrite SocketAddress trait
Thomasdezeeuw Dec 29, 2024
1b15a1a
Add back AsyncFd::connect
Thomasdezeeuw Dec 29, 2024
af81e87
Add back AsyncFd::send(_zc)
Thomasdezeeuw Dec 29, 2024
026509c
Add back AsyncFd::recv
Thomasdezeeuw Dec 29, 2024
4d4d898
Add back AsyncFd::recv_n
Thomasdezeeuw Dec 29, 2024
9765827
Remove double UnsafeCell
Thomasdezeeuw Dec 30, 2024
1c9e953
Remove fmt::Debug trait bounds
Thomasdezeeuw Dec 30, 2024
4caea42
Add sq::Queue::cancel
Thomasdezeeuw Dec 30, 2024
1917e1b
Implement DropWake for more types
Thomasdezeeuw Dec 30, 2024
08b84d0
Wrap all I/O buffers in a Buffer type
Thomasdezeeuw Dec 30, 2024
02e51d4
Implement DropWake for Buffer
Thomasdezeeuw Dec 30, 2024
f289680
Remove unused DropWake implementations
Thomasdezeeuw Dec 30, 2024
1352e26
Remove (Fd)Op::Resources to be DropWake
Thomasdezeeuw Dec 30, 2024
eb81855
Cancel in progress operations if their Futures are dropped
Thomasdezeeuw Dec 30, 2024
a720817
Rename SocketAddress::as_storage to into_storage
Thomasdezeeuw Dec 30, 2024
88e7909
Fix & ignore more Clippy lints
Thomasdezeeuw Dec 30, 2024
93ca721
Remove test example
Thomasdezeeuw Dec 30, 2024
a645ac9
Add getrandom test dependency
Thomasdezeeuw Dec 30, 2024
8ef8c13
Rename Config::_build to build_sys
Thomasdezeeuw Dec 30, 2024
9ddddf6
Update Clippy lints
Thomasdezeeuw Dec 30, 2024
2bb002f
Fix Clippy lints
Thomasdezeeuw Dec 30, 2024
e44eb0a
Set Rust version to 1.84
Thomasdezeeuw Dec 30, 2024
0c3fbfb
Use ptr::from_{ref,mut} everywhere
Thomasdezeeuw Dec 30, 2024
05fa7c6
Change CancelOperationOp arguments
Thomasdezeeuw Dec 30, 2024
6a24c8d
Reuse cancel::operation in Submissions::cancel
Thomasdezeeuw Dec 30, 2024
08d4193
Manually implement CancelOperation
Thomasdezeeuw Dec 30, 2024
9629163
Rename AsyncFd::owned_fd to fd_ref
Thomasdezeeuw Dec 30, 2024
d3bdad9
Remove unimplemented code
Thomasdezeeuw Dec 30, 2024
fd25651
Remove SOCKET_URING_OP_* constant from build.rs
Thomasdezeeuw Dec 30, 2024
493c074
Update to binggen v0.71
Thomasdezeeuw Dec 30, 2024
9d0217a
Remove reference to delete kqueue modules
Thomasdezeeuw Dec 30, 2024
f643369
Update io_uring headers
Thomasdezeeuw Dec 30, 2024
fe4dbd6
Make Future impl optional in new_operation!
Thomasdezeeuw Dec 31, 2024
950ac71
Rename with Extract to impl Extract
Thomasdezeeuw Dec 31, 2024
8383216
Implement DropWake for ReadBufPool
Thomasdezeeuw Dec 31, 2024
2dd4794
Add fd_iter_operation! macro
Thomasdezeeuw Dec 31, 2024
174749f
Add back AsyncFd::multishot_recv
Thomasdezeeuw Dec 31, 2024
f686351
Add back AsyncFd::send_all
Thomasdezeeuw Dec 31, 2024
36614b4
Make trait bound optional in operation macros
Thomasdezeeuw Dec 31, 2024
c0c25ac
Add back AsyncFd::socket_option
Thomasdezeeuw Dec 31, 2024
47ee968
Add back AsyncFd::set_socket_option
Thomasdezeeuw Dec 31, 2024
63f8071
Fix optional trait bound in new_operation! macro
Thomasdezeeuw Dec 31, 2024
1a43d93
Add back AsyncFd::shutdown
Thomasdezeeuw Dec 31, 2024
7c7685e
Add AsyncFd reference to FdOp::map_ok
Thomasdezeeuw Dec 31, 2024
a8bf5f9
Add back AsyncFd::accept
Thomasdezeeuw Dec 31, 2024
a41bd1d
Remove SubmissionQueue as resource for To{Direct,Fd}
Thomasdezeeuw Dec 31, 2024
038a304
Remove DropWake impl for SubmissionQueue
Thomasdezeeuw Dec 31, 2024
388dec8
Add back AsyncFd::multishot_accept(4)
Thomasdezeeuw Dec 31, 2024
c8ecd39
Add back AsyncFd::recv_vectored
Thomasdezeeuw Dec 31, 2024
da95039
Add back AsyncFd::recv_n_vectored
Thomasdezeeuw Dec 31, 2024
26c7474
Move filling of msghdr to io_uring code
Thomasdezeeuw Dec 31, 2024
a66d47d
Allow multiple generic is operation macros
Thomasdezeeuw Dec 31, 2024
9e44501
Add back AsyncFd::recv_from
Thomasdezeeuw Dec 31, 2024
ee1ebbc
Move iovecs to heap allocation in RecvVectoredOp
Thomasdezeeuw Dec 31, 2024
79949fa
Add back AsyncFd::recv_from_vectored
Thomasdezeeuw Dec 31, 2024
47a99cc
Add fill_recvmsg_submission
Thomasdezeeuw Dec 31, 2024
54ba90a
Remove PhantomPinned from various io_uring net ops
Thomasdezeeuw Dec 31, 2024
b1a338a
Order send calls after recv calls
Thomasdezeeuw Dec 31, 2024
eef364e
Add back AsyncFd::send_vectored
Thomasdezeeuw Dec 31, 2024
ae3157c
Add back AsyncFd::send_vectored_zc
Thomasdezeeuw Dec 31, 2024
5486475
Add AsyncFd::send_all_vectored(_zc)
Thomasdezeeuw Dec 31, 2024
1cae6c5
Add Address to SendOp
Thomasdezeeuw Dec 31, 2024
dee06f4
Add AsyncFd::send_to(_zc)
Thomasdezeeuw Dec 31, 2024
baf2ef1
Add back AsyncFd::send_to_vectored(_zc)
Thomasdezeeuw Dec 31, 2024
bfa894d
Fix Clippy lints
Thomasdezeeuw Dec 31, 2024
2b6c346
Add back poll module
Thomasdezeeuw Dec 31, 2024
d9066e7
Add poll::oneshot_poll
Thomasdezeeuw Dec 31, 2024
5c60033
Add iter_operation! macro
Thomasdezeeuw Dec 31, 2024
1d8b758
Add back multishot_poll
Thomasdezeeuw Dec 31, 2024
d21b4eb
Fix doc link in poll module docs
Thomasdezeeuw Dec 31, 2024
8cd213c
Make poll_next public
Thomasdezeeuw Dec 31, 2024
009efd0
Add msg module
Thomasdezeeuw Dec 31, 2024
4c660ae
Add msg_listener
Thomasdezeeuw Dec 31, 2024
d6fc715
Add try_send_msg
Thomasdezeeuw Dec 31, 2024
6680fdf
Add back send_msg
Thomasdezeeuw Dec 31, 2024
ca7e83f
Fix Clippy lints
Thomasdezeeuw Dec 31, 2024
2d29fd8
Use correct submit for AsyncIter operations
Thomasdezeeuw Dec 31, 2024
4c5bb64
Remove unused code
Thomasdezeeuw Dec 31, 2024
40d4535
Check queue space waking blocked futures
Thomasdezeeuw Dec 31, 2024
2107c59
Add AsyncFd::send_all_zc
Thomasdezeeuw Jan 1, 2025
81a7047
Use correct submission and completion sizes
Thomasdezeeuw Jan 1, 2025
94cffc9
Update HTTP client example
Thomasdezeeuw Jan 1, 2025
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "a10"
description = "A10 is an io_uring library."
version = "0.2.2"
version = "0.3.0"
publish = false # In development.
authors = ["Thomas de Zeeuw <[email protected]>"]
license = "MIT"
documentation = "https://docs.rs/a10"
Expand All @@ -11,6 +12,7 @@ keywords = ["io_uring", "io", "async", "non-blocking"]
categories = ["asynchronous"]
include = ["/Cargo.toml", "/src/**/*.rs", "/tests/**/*.rs", "/README.md", "/LICENSE"]
edition = "2021"
rust-version = "1.84"

[features]
default = []
Expand All @@ -25,6 +27,7 @@ log = { version = "0.4.21", default-features = false, features = ["kv_

[dev-dependencies]
std-logger = { version = "0.5.3", default-features = false }
getrandom = { version = "0.2.15", default-features = false }

[[test]]
name = "signals"
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ clippy:
--deny clippy::cargo \
--allow clippy::doc-markdown \
--allow clippy::equatable-if-let \
--allow clippy::manual-c-str-literals \
--allow clippy::missing-errors-doc \
--allow clippy::missing-panics-doc \
--allow clippy::must-use-candidate \
--allow clippy::needless-lifetimes \
--allow clippy::new-without-default \
--allow clippy::option-if-let-else \
--allow clippy::redundant-pub-crate \
--allow clippy::ref-as-ptr \
--allow clippy::single-match-else \
--allow clippy::use-self \
--allow clippy::manual-inspect \
\
--allow clippy::cast-possible-truncation \
--allow clippy::cast-possible-wrap \
--allow clippy::cast-sign-loss \

doc:
cargo doc
Expand Down
27 changes: 5 additions & 22 deletions examples/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::net::{SocketAddr, SocketAddrV4};
use std::{env, io, mem, str};
use std::net::SocketAddr;
use std::{env, io, str};

use a10::net::socket;
use a10::{AsyncFd, Ring, SubmissionQueue};
Expand All @@ -22,13 +22,8 @@ fn main() -> io::Result<()> {

// Get an IPv4 address for the domain (using blocking I/O).
let address = std::net::ToSocketAddrs::to_socket_addrs(&addr_host)?
.filter(SocketAddr::is_ipv4)
.next()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "failed to lookup ip"))?;
let address = match address {
SocketAddr::V4(address) => address,
SocketAddr::V6(_) => unreachable!(),
};

// Create our future that makes the request.
let request_future = request(ring.submission_queue().clone(), &host, address);
Expand All @@ -50,7 +45,7 @@ fn main() -> io::Result<()> {
}

/// Make a HTTP GET request to `address`.
async fn request(sq: SubmissionQueue, host: &str, address: SocketAddrV4) -> io::Result<Vec<u8>> {
async fn request(sq: SubmissionQueue, host: &str, address: SocketAddr) -> io::Result<Vec<u8>> {
// Create a new TCP, IPv4 socket.
let domain = libc::AF_INET;
let r#type = libc::SOCK_STREAM | libc::SOCK_CLOEXEC;
Expand All @@ -59,14 +54,13 @@ async fn request(sq: SubmissionQueue, host: &str, address: SocketAddrV4) -> io::
let socket: AsyncFd = socket(sq, domain, r#type, protocol, flags).await?;

// Connect.
let addr = to_sockaddr_storage(address);
socket.connect(addr).await?;
socket.connect(address).await?;

// Send a HTTP GET / request to the socket.
let host = host.split_once(':').map(|(h, _)| h).unwrap_or(host);
let version = env!("CARGO_PKG_VERSION");
let request = format!("GET / HTTP/1.1\r\nHost: {host}\r\nUser-Agent: A10-example/{version}\r\nAccept: */*\r\n\r\n");
socket.send(request, 0).await?;
socket.send_all(request, 0).await?;

// Receiving the response.
let recv_buf = socket.recv(Vec::with_capacity(8192), 0).await?;
Expand All @@ -77,14 +71,3 @@ async fn request(sq: SubmissionQueue, host: &str, address: SocketAddrV4) -> io::

Ok(recv_buf)
}

fn to_sockaddr_storage(addr: SocketAddrV4) -> libc::sockaddr_in {
// SAFETY: a `sockaddr_in` of all zeros is valid.
let mut storage: libc::sockaddr_in = unsafe { mem::zeroed() };
storage.sin_family = libc::AF_INET as _;
storage.sin_port = addr.port().to_be();
storage.sin_addr = libc::in_addr {
s_addr: u32::from_ne_bytes(addr.ip().octets()),
};
storage
}
132 changes: 51 additions & 81 deletions src/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//! [`AsyncFd::cancel_all`] to cancel all operations on a fd.

use std::future::Future;
use std::io;
use std::pin::Pin;
use std::task::{self, Poll};
use std::{fmt, io};

use crate::fd::{AsyncFd, Descriptor};
use crate::op::{op_future, poll_state, OpState};
use crate::{libc, OpIndex, QueueFull, SubmissionQueue};
use crate::op::{fd_operation, FdOperation, Operation};
use crate::{sys, OperationId, SubmissionQueue};

/// Cancelation of operations, also see the [`Cancel`] trait to cancel specific
/// operations.
Expand All @@ -33,26 +33,17 @@ impl<D: Descriptor> AsyncFd<D> {
/// Due to the lazyness of [`Future`]s it is possible that this will return
/// `Ok(0)` if operations were never polled only to start it after their
/// first poll.
///
/// [`Future`]: std::future::Future
pub const fn cancel_all<'fd>(&'fd self) -> CancelAll<'fd, D> {
CancelAll::new(self, libc::IORING_ASYNC_CANCEL_ALL)
CancelAll(FdOperation::new(self, (), ()))
}
}

// CancelAll.
op_future! {
fn AsyncFd::cancel_all -> usize,
struct CancelAll<'fd> {
// Doesn't need any fields.
},
setup_state: flags: u32,
setup: |submission, fd, (), flags| unsafe {
submission.cancel(fd.fd(), flags | D::cancel_flag());
},
map_result: |n| {
#[allow(clippy::cast_sign_loss)] // Negative values are mapped to errors.
Ok(n as usize)
},
}
fd_operation!(
/// [`Future`] behind [`AsyncFd::cancel_all`].
pub struct CancelAll(sys::cancel::CancelAllOp) -> io::Result<usize>;
);

/// Cancelation of an in progress operations.
pub trait Cancel {
Expand All @@ -67,6 +58,15 @@ pub trait Cancel {

/// Cancel this operation.
///
/// Once the returned future is completed it will asynchronously cancel the
/// related operation. This means that it *may* still return results that
/// were created before the operation was actually canceled.
///
/// For example using a TCP listener and multishot accept it's possible that
/// `MultishotAccept` will return more accepted connections after it's canceled.
/// Simply keep accepting the connections and it will return `None` after all
/// pending connections have been accepted.
///
/// If this returns `ENOENT` it means the operation was not found. This can
/// be caused by the operation never starting, due to the inert nature of
/// [`Future`]s, or the operation has already been completed.
Expand All @@ -79,8 +79,9 @@ pub trait Cancel {
/// If this is called on an [`AsyncIterator`] it will cause them to return
/// `None` (eventually, it may still return pending items).
///
/// [`Future`]: std::future::Future
/// [`AsyncIterator`]: std::async_iter::AsyncIterator
fn cancel(&mut self) -> CancelOp;
fn cancel(&mut self) -> CancelOperation;
}

/// Result of a cancelation attempt.
Expand All @@ -101,77 +102,46 @@ pub enum CancelResult {
}

/// [`Future`] behind [`Cancel::cancel`].
///
/// Once this future is completed it will asynchronously cancel the related
/// operation. This means that it *may* still return results that were created
/// before the operation was actually canceled.
///
/// For example using a TCP listener and multishot accept it's possible that
/// `MultishotAccept` will return more accepted connections after it's canceled.
/// Simply keep accepting the connections and it will return `None` after all
/// pending connections have been accepted.
///
///[`MultishotAccept::cancel`]: crate::net::MultishotAccept::cancel
#[derive(Debug)]
#[must_use = "`Future`s do nothing unless polled"]
#[allow(clippy::module_name_repetitions)] // Don't care.
pub struct CancelOp<'fd> {
sq: &'fd SubmissionQueue,
state: OpState<Option<OpIndex>>,
}
pub struct CancelOperation(pub(crate) CancelOperationState);

impl<'fd> CancelOp<'fd> {
/// Create a new `CancelOp`.
pub(crate) const fn new(sq: &'fd SubmissionQueue, op_index: Option<OpIndex>) -> CancelOp<'fd> {
CancelOp {
sq,
state: OpState::NotStarted(op_index),
impl CancelOperation {
/// Create a new `CancelOperation`.
pub(crate) fn new(sq: SubmissionQueue, op_id: Option<OperationId>) -> CancelOperation {
if let Some(op_id) = op_id {
let operation = Operation::new(sq, (), op_id);
CancelOperation(CancelOperationState::InProgress(operation))
} else {
CancelOperation(CancelOperationState::Done)
}
}
}

impl<'fd> Future for CancelOp<'fd> {
/// State of `CancelOperation`.
pub(crate) enum CancelOperationState {
/// Cancellation is already done, or the operation was never started.
Done,
/// Cancellation is in progress.
InProgress(Operation<sys::cancel::CancelOperationOp>),
}

impl Future for CancelOperation {
type Output = io::Result<()>;

fn poll(mut self: Pin<&mut Self>, ctx: &mut task::Context<'_>) -> Poll<Self::Output> {
// NOTE: don't use `poll_state!` here bacause we return `ENOENT` if it
// hasn't started.
let op_index = match self.state {
OpState::Running(op_index) => op_index,
OpState::NotStarted(Some(to_cancel_op_index)) => {
// SAFETY: this will not panic as the resources are only removed
// after the state is set to `Done`.
let result = self
.sq
.add(|submission| unsafe { submission.cancel_op(to_cancel_op_index) });
match result {
Ok(op_index) => {
self.state = OpState::Running(op_index);
op_index
}
Err(QueueFull(())) => {
self.sq.wait_for_submission(ctx.waker().clone());
return Poll::Pending;
}
}
}
// If the operation is not started we pretend like we didn't find
// it.
OpState::NotStarted(None) => {
return Poll::Ready(Err(io::Error::from_raw_os_error(libc::ENOENT)))
}
OpState::Done => poll_state!(__panic CancelOp),
};
match &mut self.0 {
CancelOperationState::Done => Poll::Ready(Ok(())),
CancelOperationState::InProgress(op) => Pin::new(op).poll(ctx),
}
}
}

match self.sq.poll_op(ctx, op_index) {
Poll::Ready(result) => {
self.state = OpState::Done;
match result {
Ok((_, _)) => Poll::Ready(Ok(())),
Err(err) => Poll::Ready(Err(err)),
}
}
Poll::Pending => Poll::Pending,
impl fmt::Debug for CancelOperation {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
const NAME: &str = "a10::CancelOperation";
match &self.0 {
CancelOperationState::Done => f.debug_struct(NAME).field("state", &"done").finish(),
CancelOperationState::InProgress(op) => op.fmt_dbg(NAME, f),
}
}
}
Loading
Loading