tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.37k stars 2.42k forks source link

Add `AsyncFd::try_io` #4719

Open jyn514 opened 2 years ago

jyn514 commented 2 years ago

Is your feature request related to a problem? Please describe.

I have a Unix socket where I want to call libc::sendmsg on the file descriptor directly. Right now, I have to use

let guard = async_fd.writable().await;
sendmsg(...);
guard.clear_ready();

which is error prone.

Describe the solution you'd like

It would be convenient to allow using try_io instead, like for UdpSocket:

async_fd.try_io(Interest::WRITABLE, || sendmsg(...));

Describe alternatives you've considered Keep using writable() guard. Implement sendmsg APIs in tokio directly (https://github.com/tokio-rs/tokio/issues/2975).

Additional context https://discord.com/channels/500028886025895936/500336333500448798/979801318375964733

Noah-Kennedy commented 2 years ago

This seems like a good idea.

gpyrros commented 2 years ago

I'd like to give this a try

Noah-Kennedy commented 2 years ago

@jyn514 we have unix socket types, why not use those for your use case?

jyn514 commented 2 years ago

@Noah-Kennedy I have a trait that abstracts over different socket types.

Noah-Kennedy commented 2 years ago

Ah ok