Skip to content
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

Different RecvError::Finished behavior for embassy-net tcp recv() vs recv_with() #3252

Open
mattiasgronlund opened this issue Aug 13, 2024 · 0 comments

Comments

@mattiasgronlund
Copy link
Contributor

Hi,

Is there a reason for the difference regarding Err(tcp::RecvError::Finished) for tcp.rs read_with(...):

Poll::Ready(match s.recv(unwrap!(f.take())) {
    // Connection reset. TODO: this can also be timeouts etc, investigate.
    Err(tcp::RecvError::Finished) | Err(tcp::RecvError::InvalidState) => {
        Err(Error::ConnectionReset)
    }
    Ok(r) => Ok(r),
})

and tcp.rs read(...):

    ...
    // EOF
    Err(tcp::RecvError::Finished) => Poll::Ready(Ok(0)),
    // Connection reset. TODO: this can also be timeouts etc, investigate.
    Err(tcp::RecvError::InvalidState) => Poll::Ready(Err(Error::ConnectionReset)),

Might it be so that, Err(tcp::RecvError::Finished) indicates when other end has closed it's write side, i.e. EOF, which read() indicates, but read_recv() should not distinguish between other end closed its write side and a ConnectionReset)?

I suppose read() does the right thing, even if it feels a bit error prone to indicate a non recoverable EOF with Ok(0) instead of ConnectionReset (I suppose I am not the only who managed forget the Ok(0) case and locked up my task in a tight loop).

In any case, thanks for the impressive work put into embassy-rs!

BR
Mattias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant