tokio icon indicating copy to clipboard operation
tokio copied to clipboard

Add `AsyncFd::try_io`

Open jyn514 opened this issue 3 years ago • 5 comments

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

jyn514 avatar May 27 '22 18:05 jyn514

This seems like a good idea.

Noah-Kennedy avatar May 28 '22 01:05 Noah-Kennedy

I'd like to give this a try

Pyrromanis avatar Jun 16 '22 20:06 Pyrromanis

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

Noah-Kennedy avatar Jun 16 '22 21:06 Noah-Kennedy

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

jyn514 avatar Jun 16 '22 22:06 jyn514

Ah ok

Noah-Kennedy avatar Jun 16 '22 22:06 Noah-Kennedy