-
Notifications
You must be signed in to change notification settings - Fork 739
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
Wait for messages in the error queue #1672
Comments
Per the
So However, I don't think you need separate file descriptor for this. Looking through |
you're right that the second socket is not technically needed, but I think it's the only current way to have this mechanism work with tokio. Unless I'm mistaken tokio would need an retrieving the content of the error message works as you say, and is not a problem at all. it's really that we must wait for the socket to report that the time stamp is available. these are the relevant events as captured by strace
So just to confirm: to your knowledge, mio today provides everything required for tokio to support awaiting on messages arriving into the error queue? |
I'm not about Tokio, but for Mio the "error" interest is always registered (by the OS) and can be retrieved using
I think so. The |
I did some more digging. I think tokio-rs/tokio#5566 if/when it lands provides a bunch of useful features. In particular it allows this pattern on file descriptors let guard = async_fd.ready(Interest::PRIORITY).await.unwrap();
dbg!(guard.ready()); with some hackery, I can indeed get an error event to show
However, there isn't really a good way to await error readiness that I can see. In tokio, to await something you need to provide an interest. Today this is defined as
this interest is then turned into a ready value, and this ready value is matched agains incoming events, to see if anything matches. pub(crate) fn from_interest(interest: Interest) -> Ready {
let mut ready = Ready::EMPTY;
if interest.is_readable() {
ready |= Ready::READABLE;
ready |= Ready::READ_CLOSED;
}
if interest.is_writable() {
ready |= Ready::WRITABLE;
ready |= Ready::WRITE_CLOSED;
}
#[cfg(any(target_os = "linux", target_os = "android"))]
if interest.is_priority() {
ready |= Ready::PRIORITY;
ready |= Ready::READ_CLOSED;
}
// NOTE: this is a line I added
ready |= Ready::ERROR;
ready
} The So the above code just always also awaits error readiness, but that means there is no targeted way to wait for just error readiness, and error readiness would be visible to users that just want read/write/priority readiness. So, I'm not really sure what to do with that. Maybe there is a solution strictly on the tokio side, but it's not obvious to me. |
I think you should wait for read readiness, that should trigger error as well. But I'm not sure how the interaction with two file descriptors (user space) work, because epoll's trigger works on file descriptions (kernel side), their might be some weirdness when dealing with two file descriptors pointing to the same file description, I'm not sure.
I'm repeating myself here, but You can try
|
right, I'll have to figure something out strictly on the tokio side then. thanks for your help here, and all your work on mio! |
I work on ntpd-rs, an NTP implementation in rust. A big part of how it works is to configure a UDP socket to record timestamps when a message is sent or received, and then retrieving these timestamps. Based on the documentation, the timestamp is not available immediately (we've observed this for external hardware clocks, software timestamps do seem to be effectively instant).
These timestaps end up in the error queue (
libc::MSG_ERRQUEUE
) of the socket. Tokio does not have a way to await or read these messages currently. Our fix for the time being is to configure an extra file descriptor that becomes readable when the UDP socket encounters the EPOLLERR event.full code here
We'd like to add primitives to
mio
andtokio
to eliminate this unsafe code from our repository. A first step would be to be able to await messages in the error queue, which I think requires exposing the EPOLLERR event.The #1647 PR adds
Interest::PRIORITY
. I'd like to also makeInterest::ERROR
available in much the same way.Does that seem reasonable? I'd be happy to take on the actual implementation work.
The text was updated successfully, but these errors were encountered: