Skip to content

feat(agnostic-net)!: named futures + bound-minimization - #53

Open
al8n wants to merge 3 commits into
mainfrom
feat/agnostic-net-named-futures
Open

al8n wants to merge 3 commits into
mainfrom
feat/agnostic-net-named-futures

Conversation

@al8n

@al8n al8n commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

No description provided.

Convert UdpSocket's async methods to tower-style named associated futures so
each future's Send-ness is structural and boundable at the use site, and drop
the blanket Send + Sync from the trait. First slice of the embedded/no_std
named-futures rollout (TcpStream/TcpListener follow); unblocks a future
embassy-net (!Send) backend.

- The 8 async methods return named GAT futures (Bind/Connect/Recv/RecvFrom/
  Send/SendTo/Peek/PeekFrom). The I/O futures are zero-cost wrappers over the
  poll primitives; bind/connect/send_to are pin-projected state machines that
  hold ToSocketAddrs' own named resolution future -- no Box, no nightly TAIT.
- Add poll_send (connected send; a plain `send` avoids EISCONN on BSD/macOS
  where `sendto` on a connected socket fails) and poll_peek_from primitives.
- bind: std bind (non-blocking) + TryFrom; connect: socket2's sync UDP connect.
- The relaxed Send + Sync surfaces only at genuine use sites: hickory's
  DnsUdpSocket / RuntimeProvider impls (agnostic-dns) and the UDP test spawn
  sites carry explicit `where N::UdpSocket: Send + Sync` bounds.

BREAKING CHANGE: UdpSocket's async methods return named future types instead of
`impl Future + Send`, and the trait no longer requires Send + Sync. Generic
code that spawns a socket on a multi-threaded executor must add an explicit
Send bound.
@codecov

codecov Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.71955% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.30%. Comparing base (33cce8d) to head (8a1eb84).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
agnostic-net/src/udp.rs 77.30% 32 Missing ⚠️
agnostic-net/src/async_io.rs 74.35% 10 Missing ⚠️
agnostic-net/src/tcp.rs 91.66% 10 Missing ⚠️
agnostic-net/src/smol/udp.rs 62.50% 6 Missing ⚠️
agnostic-net/src/smol/tcp_listener.rs 84.61% 2 Missing ⚠️
agnostic-net/src/tokio/udp.rs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   52.82%   55.30%   +2.47%     
==========================================
  Files          42       42              
  Lines        1861     2094     +233     
==========================================
+ Hits          983     1158     +175     
- Misses        878      936      +58     
Files with missing lines Coverage Δ
agnostic-dns/src/lib.rs 47.27% <ø> (ø)
agnostic-net/src/lib.rs 37.50% <ø> (-10.12%) ⬇️
agnostic-net/src/tokio/tcp_listener.rs 100.00% <100.00%> (+18.18%) ⬆️
agnostic-net/src/tokio/tcp_stream.rs 100.00% <100.00%> (ø)
agnostic-net/src/tokio/tcp_stream/owned.rs 86.66% <100.00%> (+1.48%) ⬆️
agnostic-net/src/tokio/udp.rs 94.44% <87.50%> (-5.56%) ⬇️
agnostic-net/src/smol/tcp_listener.rs 90.47% <84.61%> (-9.53%) ⬇️
agnostic-net/src/smol/udp.rs 68.57% <62.50%> (+0.15%) ⬆️
agnostic-net/src/async_io.rs 90.00% <74.35%> (-4.66%) ⬇️
agnostic-net/src/tcp.rs 92.30% <91.66%> (+1.19%) ⬆️
... and 1 more

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31a21e8...8a1eb84. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

al8n added 2 commits June 25, 2026 22:55
The always-compiled Bind/Connect/SendTo futures use pin-project-lite, so make
it an unconditional dependency (it was optional, pulled only by tokio/smol).
The future constructors are called only from the runtime-backend macro, so
gate them behind `any(feature = "tokio", feature = "smol")` to avoid a
dead-code error under `--no-default-features` (the crate denies warnings).
… and TcpListener

Apply the tower-style named-future conversion to TcpStream, TcpListener,
OwnedReadHalf, OwnedWriteHalf, and ReuniteError: every async method returns a
named future, and Send + Sync is dropped from the traits' supertraits and from
the method futures/streams (boundable at the use site instead).

- New named-future associated types: TcpStream::{Connect, ConnectTimeout, Peek},
  TcpListener::{Bind, Accept, Incoming, IntoIncoming}, OwnedReadHalf::Peek.
- New poll primitives: TcpStream::{poll_peek, poll_write_ready},
  TcpListener::poll_accept, OwnedReadHalf::poll_peek.
- connect is a non-blocking-connect state machine (socket2 + set_nonblocking +
  tolerate EINPROGRESS via the existing rustix dep, then poll_write_ready +
  take_error) -- zero-cost on stable. bind reuses the sync std-bind + TryFrom.
- Future types are namespaced under `agnostic_net::{udp,tcp}::*` (the traits
  stay at the crate root) to avoid the Bind/Connect/Peek name collision.
- The relaxed Send + Sync surfaces only at the use sites: hickory's DnsTcpStream
  / RuntimeProvider impls (agnostic-dns) and the TCP test spawn sites carry
  explicit `where N::TcpStream: Send + Sync` bounds.

BREAKING CHANGE: TcpStream/TcpListener async methods return named future types
instead of `impl Future + Send`, the traits no longer require Send + Sync, and
the UDP/TCP future types moved from the crate root into the `udp`/`tcp` modules.
@al8n al8n changed the title feat(agnostic-net)!: named futures + bound-minimization for UdpSocket feat(agnostic-net)!: named futures + bound-minimization Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant