Skip to content

feat(io): add traits for reading/writing with ancillary data#717

Merged
George-Miao merged 7 commits intocompio-rs:masterfrom
fantix:io-socket-trait
Mar 25, 2026
Merged

feat(io): add traits for reading/writing with ancillary data#717
George-Miao merged 7 commits intocompio-rs:masterfrom
fantix:io-socket-trait

Conversation

@fantix
Copy link
Copy Markdown
Contributor

@fantix fantix commented Feb 28, 2026

This adds runtime-agnostic stream APIs for reading/writing data with an ancillary buffer:

  • AsyncReadAncillary::read_with_ancillary
  • AsyncReadAncillary::read_vectored_with_ancillary
  • AsyncWriteAncillary::write_with_ancillary
  • AsyncWriteAncillary::write_vectored_with_ancillary

Such traits are behind a compio-io feature gate ancillary. They are automatically implemented for TcpStream and UnixStream in compio-net. UdpSocket has its own cmsg API, and UDP is also not a stream.

One implicit behavior in the write APIs is that, it accepts empty control buffers, in which case, the impl will use a null pointer with 0 length for ancillary data fields. See this commit for more details.

Comment thread compio-net/src/udp.rs
@discosultan
Copy link
Copy Markdown

Been looking for cmsg methods on tcp stream as well 👍

Comment thread compio-io/src/socket.rs Outdated
Comment thread compio-net/src/udp.rs
Comment thread compio-net/src/unix.rs Outdated
@fantix fantix force-pushed the io-socket-trait branch 2 times, most recently from 2748a7c to 6914654 Compare March 3, 2026 02:34
@fantix fantix force-pushed the io-socket-trait branch from abaf689 to b41d62c Compare March 4, 2026 02:58
@Berrysoft Berrysoft added package: net Related to compio-net package: io Related to compio-io labels Mar 4, 2026
@Berrysoft Berrysoft added this to the v0.19 milestone Mar 11, 2026
@fantix fantix force-pushed the io-socket-trait branch 4 times, most recently from 6d5abc7 to a40dbc4 Compare March 22, 2026 01:32
fantix added 3 commits March 24, 2026 21:11
This is not done in a way of making control param optional because
send_with_ancillary() semantically requires a control buffer, but
at the same time, send_with_ancillary() with empty control buffer
is not practically identical to just send() as the latter may use
different impl like send_zc in iour. Therefore, I decided to
implicitly allow empty cmsg buffers as something like "enforce
sendmsg impl, but send without control buffer".
@fantix fantix changed the title feat(io): add socket traits for cmsg send/recv feat(io): add traits for reading/writing with ancillary data Mar 25, 2026
@fantix fantix marked this pull request as ready for review March 25, 2026 04:38
Copy link
Copy Markdown
Member

@Berrysoft Berrysoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But isn't the method name too long?

Also need @George-Miao to review.

Copy link
Copy Markdown
Member

@George-Miao George-Miao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I can't think of any shorter names tho, unless someone has better idea, let's keep it this way.

@George-Miao George-Miao merged commit f75d13c into compio-rs:master Mar 25, 2026
67 checks passed
@fantix fantix deleted the io-socket-trait branch March 25, 2026 16:02
@github-actions github-actions Bot mentioned this pull request Mar 25, 2026
@github-actions github-actions Bot mentioned this pull request Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: io Related to compio-io package: net Related to compio-net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants