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

return error also in the closing state #881

Merged
merged 2 commits into from
Sep 4, 2023
Merged

Conversation

stlankes
Copy link
Contributor

@stlankes stlankes commented Sep 2, 2023

If smoltcp receives a FIN message, the socket changes the state to the closing, but the socket is still active. To close the socket, the kernel returns a error if the socket is in the closing state.

The PR should solve issue #880

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return Ok(0) in both cases.

From Read::read:

If n is 0, then it can indicate one of two scenarios:

  1. This reader has reached its “end of file” and will likely no longer be able to produce bytes. Note that this does not mean that the reader will always no longer be able to produce bytes. As an example, on Linux, this method will call the recv syscall for a TcpStream, where returning zero indicates the connection was shut down correctly. While for File, it is possible to reach the end of file and get zero as result, but if more data is appended to the file, future calls to read will return more data.
  2. The buffer specified was 0 bytes in length.

From Write::write:

A return value of Ok(0) typically means that the underlying object is no longer able to accept bytes and will likely not be able to in the future as well, or that the buffer provided is empty.

Note that the example from the issue does not result in an error on Linux either.

@stlankes
Copy link
Contributor Author

stlankes commented Sep 3, 2023

You are right. I fixed it.

If smoltcp receives a FIN message, the socket changes the state
to the `closing`, but the socket is still active. To close the
socket, the kernel returns a error if the socket is in the
closing state.

The PR should solve issue hermit-os#880
Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really return an error on FIN-WAIT-1 etc.? It might be better to not match against the TCP state directly and instead use may_send and may_receive. What do you think?

https://github.com/smoltcp-rs/smoltcp/blob/28a5dd17ab7808bec6d7f944b8ef4289881d405f/examples/httpclient.rs#L84-L119

@mkroening mkroening added this pull request to the merge queue Sep 4, 2023
Merged via the queue into hermit-os:main with commit 012430a Sep 4, 2023
8 checks passed
@stlankes stlankes deleted the testtcp branch September 4, 2023 08:47
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

Successfully merging this pull request may close these issues.

None yet

2 participants