-
-
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 function for listening to socket readiness events #2968
Comments
Progress on this issue:
|
It's still not entirely clear to me whether it's possible to use this API to wait for just HUP. I managed to get something working here, but it's suboptimal: MaterializeInc/materialize#5235 The tl;dr is what you have to write currently is something like this, which polls fn write_stream(conn: TcpStream, stream: &dyn Stream<Item = Vec<u8>>) -> Result<(), &'static str> {
loop {
match time::timeout(Duration::from_secs(1), stream.next()).await {
Ok(None) => return Ok(()),
Ok(Some(data)) => conn.write_all(data).await,
Err(_) => {
let ready = conn.ready(Interest::READABLE).await?;
if ready.is_read_closed() {
return Err("conn broke");
}
}
}
}
} But ideally you'd be able to block on the fn write_stream(conn: TcpStream, stream: &dyn Stream<Item = Vec<u8>>) -> Result<(), &'static str> {
loop {
select! {
msg = stream.next() => match msg {
None => return Ok(()),
Some(data) => conn.write_all(data).await,
}
_ = conn.ready(Interest::READ_CLOSED) => return Err("conn broke"),
}
}
} |
Oh, by the way, #3246 merged, so I think technically this issue is complete. I can file a new issue for the HUP thing, if you prefer. |
Yeah, please file a new issue. |
TcpStream
,TcpListener
,UdpSocket
, ... should provide async functions for receiving readiness events.Something like:
This would allow the user to hook into arbitrary readiness events and receive notifications such as HUP.
We also should provide
poll_ready_ready
andpoll_write_ready
for each socket type.Open question
Should the ready function return a
ReadyGuard
similar toAsyncFd
or should it clear readiness in thetry_read
/try_write
function?Refs: #2903
The text was updated successfully, but these errors were encountered: