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 UdpSocket::{try_send,try_send_to}
methods
#1979
net: Add UdpSocket::{try_send,try_send_to}
methods
#1979
Conversation
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Hm this seems a little tricky due to Mio's Before checking if data can even be sent, the binding status of the source is expected to have been registered This has been changed in v0.7.x and will not be an issue.. Need to figure out what makes sense for this while still on 0.6. |
Don’t we register in inititialization?
…On Tue, Dec 17, 2019 at 4:58 PM Kevin Leimkuhler ***@***.***> wrote:
Hm this seems a little tricky due to Mio's UdpSocket::{send,recv} methods
in v0.6.x
<https://github.com/tokio-rs/mio/blob/8078b9034dfbe4e93277877a34ea803b55c7e3a9/src/sys/windows/udp.rs#L90-L91>
.
Before checking if data can even be sent, the binding status of the source
is expected to have been registered
<https://github.com/tokio-rs/mio/blob/8078b9034dfbe4e93277877a34ea803b55c7e3a9/src/sys/windows/udp.rs#L100>
This has been changed in v0.7.x and will not be an issue.. Need to figure
out what makes sense for this while still on 0.6.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1979?email_source=notifications&email_token=AAABQJGGDF3VOMMHCHLR6KTQZFYSZA5CNFSM4J4DAL52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHEPN5A#issuecomment-566818548>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABQJDDATJGSEKRU5BMX4DQZFYSZANCNFSM4J4DAL5Q>
.
|
Edit: This was incorrect. This commet resolves the issue. |
@kleimkuhler can we change that to register earlier? Maybe in |
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
@carllerche The issue was not registration. I restrucuted the test to work
|
I am not completely sure what the issue is but it seems like it is because mio does not track how many tasks are concurrently expressing interest for the same object? |
Motivation
It is currently not possible send data on a single
UdpSocket
from multiplelocations because the
send
methods take&mut self
. This change introducestry_send
methods that take&self
.Solution
Closes #1624
The
&mut self
requirements onsend
andsend_to
are enforced so that onetask cannot deadlock another.
If two tasks concurrently register interest in sending data and immediately
sending data would block, one task will overwrite the other's interest. This
will cause the task that "won" the race in registering to deadlock. While this
is an uncommon case, it introduces the possibility of it happening and should be
avoided.
The new
try_send
andtry_send_to
methods take&self
and sidestep the aboveissue by not registering the tasks interest.
try_send
immediately returnsthe number of bytes sent or an error if one occurred.
try_send_to
firstresolves the given target to a
SocketAddr
, and then immediately tries sendingthe data.
try_recv
andtry_recv_from
These methods would be equivalent to what is being introduced in this change,
but for receving data on a
UdpSocket
. This is a less common case, but if itmakes sense to include them in this PR then I can add them.
Signed-off-by: Kevin Leimkuhler kleimkuhler@icloud.com