-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: add TcpStream::ready and non-blocking ops #3130
Conversation
Sketch out splitting up awaiting for readiness and performing the operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You add an try_read
, but not try_write
?
Edit: I see you mention try_write
.
@Darksonn I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at everything in this review, but here is some.
Co-authored-by: Alice Ryhl <alice@ryhl.io>
Adds `ready()`, `readable()`, and `writable()` async methods for waiting for socket readiness. Adds `try_send`, `try_send_to`, `try_recv`, and `try_recv_from` for performing non-blocking operations on the socket. This is the UDP equivalent of #3130.
Adds `ready()`, `readable()`, and `writable()` async methods for waiting for socket readiness. Adds `try_send`, `try_send_to`, `try_recv`, and `try_recv_from` for performing non-blocking operations on the socket. This is the UDP equivalent of #3130.
Adds function to await for readiness on the TcpStream and non-blocking read/write functions.
async fn TcpStream::ready(Interest)
waits for socket readiness satisfying any of the specified interest. There are also two shorthand functions,readable()
andwritable()
.Once the stream is in a ready state, the caller may perform non-blocking operations on it using
try_read()
andtry_write()
. These function returnWouldBlock
if the stream is not, in fact, ready.The await readiness function are similar to
AsyncFd
, but do not require a guard. The guard inAsyncFd
protect against a potential race between receiving the readiness notification and clearing it. The guard is needed as Tokio does not control the operations. WithTcpStream
, thetry_read()
andtry_write()
function handle clearing stream readiness as needed.This also exposes
Interest
andReady
, both defined in Tokio as wrappers for Mio types. These types will also be useful for fixing #3072 .Other I/O types, such as
TcpListener
,UdpSocket
,Unix*
should get similar functions, but this is left for later PRs.Refs: #2968