-
-
Notifications
You must be signed in to change notification settings - Fork 396
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
Do not require &mut self in AsyncUdpSocket::poll_send #1519
Conversation
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.
Seems reasonable to me!
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.
We should generally avoid locking in I/O, but this should be well off the hotpath so I think it's fine. Easy to swap in an atomic microsecond counter or something later if we need to.
Can you elaborate a bit on why implementing |
The reason is that I have multiple different transports hiding behind it in my implementation. Depending on the hole punching/NAT situation it will either use a relay or actual UDP sockets, but those might change as well, depending on current connectivity. So my solution is to use an |
If you have |
#[derive(Clone)]
struct MyConn {
inner: Arc<RwLock<UdpSocket>>,
}
impl quinn::AsyncUdpSocket for MyConn {
// ..
} |
I am currently running into the issue that it requires a large amount of locking when implementing a custom
AsyncUdpSocket
, becausepoll_send
at the moment requires&mut self
.So I looked into the reason that is (given that a regular
UdpSocket::send
does not require mutable access), and it turned out to only need write access to thelast_send_error
time. As the simplest option I put that behind aMutex
, which I think will be fine, but open to discussion of other variants, e.g. storing it in an atomic type or similar.