Skip to content

feat: implement readable and writable for Tcp Split - #388

Open
ndrscodes wants to merge 5 commits into
monoio-rs:masterfrom
ndrscodes:feat-tcp-split-write-readable
Open

feat: implement readable and writable for Tcp Split#388
ndrscodes wants to merge 5 commits into
monoio-rs:masterfrom
ndrscodes:feat-tcp-split-write-readable

Conversation

@ndrscodes

@ndrscodes ndrscodes commented Apr 5, 2026

Copy link
Copy Markdown

Problem

TcpOwnedReadHalf and TcpOwnedWriteHalf currently do not support waiting for the stream to be readable or writable, as the split does not expose the underlying readable and writable functions.

Design

We can safely expose both functions on the Read and Write split of the TcpStream since this does not require manipulation of a shared Fd and merely exposes already-implemented functions.

Solution

Adds proxy functions to TcpStream's writable(relaxed) and readable(relaxed) functions for TcpOwnedWriteHalf and TcpOwnedReadHalf.

@CLAassistant

CLAassistant commented Apr 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Lzzzzzt

Lzzzzzt commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Hello, there are some clippy errors, could you help please to fix them, thank you very much.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes stream readiness waiting on TcpStream’s owned split halves so users can await read/write readiness via TcpOwnedReadHalf and TcpOwnedWriteHalf.

Changes:

  • Add TcpOwnedReadHalf::readable(relaxed) as a proxy to TcpStream::readable(relaxed).
  • Add TcpOwnedWriteHalf::writable(relaxed) as a proxy to TcpStream::writable(relaxed).
  • Introduce accompanying Rustdoc describing readiness semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +32
/// Note: Do not use it before every io. It is different from other runtimes!
///
/// Everytime call to this method may pay a syscall cost.
/// In uring impl, it will push a PollAdd op; in epoll impl, it will use use
/// inner readiness state; if !relaxed, it will call syscall poll after that.

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

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

Doc comment typos: "Everytime" should be "Every time", and "use use" contains a duplicated word. Please fix these in the new docs to avoid propagating the typo further.

Copilot uses AI. Check for mistakes.
Comment thread monoio/src/net/tcp/split.rs Outdated
/// If you want to do io by your own, you must maintain io readiness and wait
/// for io ready with relaxed=false.
#[inline]
pub async fn writable(&self, relaxed: bool) -> Result<(), io::Error> {

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

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

The new writable API returns Result<(), io::Error> while other socket readiness APIs use io::Result<()>. Please align this signature to io::Result<()> for consistency.

Suggested change
pub async fn writable(&self, relaxed: bool) -> Result<(), io::Error> {
pub async fn writable(&self, relaxed: bool) -> io::Result<()> {

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +69
/// Note: Do not use it before every io. It is different from other runtimes!
///
/// Everytime call to this method may pay a syscall cost.
/// In uring impl, it will push a PollAdd op; in epoll impl, it will use use
/// inner readiness state; if !relaxed, it will call syscall poll after that.

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

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

Doc comment typos duplicated from the readable docs (e.g., "Everytime" and "use use"). Since this is newly added documentation, please correct the wording here as well.

Copilot uses AI. Check for mistakes.
Comment thread monoio/src/net/tcp/split.rs Outdated
Comment on lines +38 to +40
pub async fn readable(&self, relaxed: bool) -> Result<(), io::Error> {
unsafe { &*self.0.get() }.readable(relaxed).await
}

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

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

New public APIs (TcpOwnedReadHalf::readable / TcpOwnedWriteHalf::writable) aren’t covered by tests yet. There are existing readiness tests for TcpStream/TcpListener (e.g. monoio/tests/tcp_echo.rs::rw_able), so adding a similar test for the split halves would help prevent regressions and ensure these proxies work across drivers.

Copilot uses AI. Check for mistakes.
Comment thread monoio/src/net/tcp/split.rs Outdated
Comment on lines +38 to +40
pub async fn readable(&self, relaxed: bool) -> Result<(), io::Error> {
unsafe { &*self.0.get() }.readable(relaxed).await
}

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

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

The new readable API returns Result<(), io::Error> while the rest of this module (and TcpStream::{readable,writable}) use io::Result<()>. Please switch to io::Result<()> here for consistency and simpler signatures.

Copilot uses AI. Check for mistakes.
@ndrscodes

Copy link
Copy Markdown
Author

Hello, there are some clippy errors, could you help please to fix them, thank you very much.

Hi @Lzzzzzt. The clippy errors do not stem from my commit and fixing them would pollute this PR. Should I still include the fix here?

@ndrscodes

Copy link
Copy Markdown
Author

@Lzzzzzt I created #397 to address the clippy issue as it affects every PR right now.

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.

4 participants