net: support socket reuse and I/O timeouts - #461
Closed
xuchang-vivo wants to merge 1 commit into
Closed
Conversation
Contributor
Author
|
build_prs |
|
Job is started, see https://github.com/vivoblueos/kernel/actions/runs/32960999069. |
|
✅ All jobs completed successfully, see https://github.com/vivoblueos/kernel/actions/runs/32960999069. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SO_REUSEADDRas a compatibility option while preserving the current one-listener-per-endpoint behavior.SO_RCVTIMEOandSO_SNDTIMEOfor blocking TCP, UDP, and ICMP send/receive operations.Motivation
Rust
TcpListener::bind()enablesSO_REUSEADDRbefore binding. BlueOS previously returnedENOPROTOOPT, so otherwise valid listeners failed before reachingbind().The socket timeout values were stored but never enforced. A blocked operation waited indefinitely, and the connection-wide reply object could retain state across multiple calls. This showed up as agent-loop requests hanging after several HTTP/TLS rounds.
Reuse-address behavior
smoltcp does not expose endpoint-sharing semantics equivalent to a host TCP stack. This change therefore accepts and reports the option for API compatibility but does not allow multiple listeners to bind the same endpoint. BlueOS still permits one listener per endpoint.
Timeout and buffer-lifetime safety
Each operation moves through explicit waiting, executing, completed, and cancelled states.
This prevents a timed-out syscall from returning while the network thread may still access the caller-owned send or receive buffer.
Related work
ConnectionError::TimeoutasETIMEDOUTacross the syscall boundary.This PR does not include BME280 or other sensor changes.
References
Testing
rustfmt --edition 2021 --check kernel/src/net/connection.rs kernel/src/net/syscalls.rs kernel/src/net/smoltcp/socket/tcp.rs kernel/src/net/smoltcp/socket/udp.rs kernel/src/net/smoltcp/socket/icmp.rsgit diff --check