-
Notifications
You must be signed in to change notification settings - Fork 747
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
feat(embassy-net): Implement wait_recv_ready()
+ wait_send_ready()
for UdpSocket and wait_read_ready()
+ wait_write_ready()
for TcpSocket
#3368
Conversation
I think the implementation is correct. My only regret is that this PR implements the absolute minimum necessary for How about extending the PR with a similar impl for the TCP sockets. =========== Implementing a similar While we don't strictly need this, it would be nice to have I think if not for anything else, then for symmetry with Unfortunately, |
I'd be more than happy to implement the TCP part and take a look at implementing a The issue is that I don't have any code to test the TCP socket, for readable and writable (same for raw). In edge-net for example, the |
Actually, looking at it, I think embassy/embassy-net/src/tcp.rs Lines 392 to 396 in 0ede847
I first believed embassy/embassy-net/src/tcp.rs Lines 379 to 382 in 0ede847
BUT The documentation is misleading, as smoltcp::socket::tcp::Socket::may_send() states the following: /// However, it does not make any guarantees about the state
/// of the transmit buffer, and even if it returns true, [send](#method.send) may
/// not be able to enqueue any octets |
d89eb78
to
177baa5
Compare
So I'm not familiar with
Would calling |
TLDR: No, but the two tasks, where each is e.g. calling Elaboration: Formally speaking, that's not a problem and the code would still work correctly. This does not mean you should do it (because of the high CPU usage). (UPDATE: Removed a paragraph which is about However - yes - at least my primary use case of If the futures are each spawned in a separate task - then - yes - there will be high-usage CPU dragons. :-) |
Argh, I need to take some rest. :-) No. My case is NOT about two futures calling So |
For TCP we should implement the official embedded-io ReadReady, WriteReady. If we want to extend that with "async wait for", i'd name them // inherent methods
fn read_ready(&self) -> bool;
fn poll_read_ready(&self, cx: &mut Context) -> Poll<()>;
async fn wait_read_ready(&self);
fn write_ready(&self) -> bool;
fn poll_write_ready(&self, cx: &mut Context) -> Poll<()>;
async fn wait_write_ready(&self);
// ReadReady trait impl
fn read_ready(&self) -> bool;
// WriteReady trait impl
fn write_ready(&self) -> bool; The API for UDP should be the same for consistency, except:
so i'd suggest: fn recv_ready(&self) -> bool;
fn poll_recv_ready(&self, cx: &mut Context) -> Poll<()>;
async fn wait_recv_ready(&self);
fn send_ready(&self) -> bool;
fn poll_send_ready(&self, cx: &mut Context) -> Poll<()>;
async fn wait_send_ready(&self); |
Not that I've been asked, but I'm fine with any names. The |
177baa5
to
e2f4101
Compare
I've renamed the functions to use the them It's only missing: fn poll_send_ready(&self, cx: &mut Context) -> Poll<()>;
async fn wait_send_ready(&self); for UDP to have the full readable / writable async wait on both TCP and UDP sockets. I'll have to check what's the best way to check if a UDP connection is ready to send |
it's |
I can use |
e2f4101
to
45d32c5
Compare
…` for UdpSocket - Provides `pub async fn wait_recv_ready(&self) -> ()` and `pub fn poll_recv_ready(&self, cx: &mut Context<'_>) -> Poll<()>`. This allows polling / waiting on a socket until it can be read, without dequeuing any packets. - Provides `pub async fn wait_send_ready(&self) -> ()` and `pub fn poll_send_ready(&self, cx: &mut Context<'_> -> Poll<()>` This allows polling / waiting on a socket until it becomes writable.
…reflect actual behavior from smoltcp
…)` for TcpSocket
45d32c5
to
712fa08
Compare
readable()
for UdpSocketwait_recv_ready()
+ wait_send_ready()
for UdpSocket and wait_read_ready()
+ wait_write_ready()
for TcpSocket
@Dirbaio @AnthonyGrondin Is there anything stopping this from merging? I have this one comment which might be a concern. Hopefully, I just misunderstand the |
okay i've checked smoltcp's source and this seems to be a bug indeed. Filed smoltcp-rs/smoltcp#1004, will fix later. |
This provides a
readable()
implementation forUdpSocket
, as discussed on Matrix.This API allows a library maintainer or the end user to wait / poll a socket to see if it is readable, without dequeuing any packet. This is useful for offloading packet processing in a different part of the application.
/cc @ivmarkov