-
Notifications
You must be signed in to change notification settings - Fork 420
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
How to distinguish FIN and RST closes in recv? #349
Comments
If I recall correctly, once you've exhausted the receive buffer, if the remote end sent FIN, then |
That won't work if we've closed our side before. Consider this:
... which can happen both with receiving FIN or RST. |
Yep, that's true. Let's figure out an API for this case, then. |
Option 1: Signal EOF with a new error
Option 2: Signal EOF by returning 0 bytes, like
Option 1 is closest to the current smoltcp behavior. |
Both of these are changes that would break all existing code, right? |
Yes :( Option 1 would be the least breaking. It won't break code that handles any recv error as "okay, no more data" but it will break code that looks at what actual error is returned. There's Option 3:
Hoever, it feels weird to me to have the extra is_eof() method. It's very unlike any other io api/trait out there. All of them signal EOF in the return value of What's the project's policy on breaking changes? My PR #346 is a breaking change too. |
Breaking changes on the system/PHY side are generally fine as long as they aren't silently breaking code. Breaking changes on the socket side are much less fine, especially if they do silently break existing code.
I've considered these options and I think I would prefer adding |
Makes sense, thanks for the clarification.
Cool! I'll try to send a PR. There are hairy edge-cases, like: we receive 3 packets: seq 0-100, seq 200-300 with FIN, and a RST. In this case the app should read 0-100 and then get Err::Illegal even if we've received a FIN, because it hasn't read the entire data because we're missing a fragment. |
Yep, this isn't very easy to implement unfortunately. |
When reading data from a
TcpSocket
with therecv_*
functions,Error::Illegal
is returned when there's no more readable data.The issue is AFAICT there's no way to distinguish whether the remote end gracefully closed the connection with a FIN packet, or the connection was aborted with a RST packet, or other error cases (idle timeout, etc).
A common use case for this is when downloading a file. You want to know whether you have received the whole file (gracefully closed with FIN) or only part of it because the connection died for some other reason, so you don't silently truncate the file.
recv_*
functions being able to signalEOF
vs an error condition, like the Berkeley sockets API.The text was updated successfully, but these errors were encountered: