Skip to content

net: support socket reuse and I/O timeouts - #461

Closed
xuchang-vivo wants to merge 1 commit into
vivoblueos:mainfrom
xuchang-vivo:xc/socket-reuseaddr-timeouts
Closed

net: support socket reuse and I/O timeouts#461
xuchang-vivo wants to merge 1 commit into
vivoblueos:mainfrom
xuchang-vivo:xc/socket-reuseaddr-timeouts

Conversation

@xuchang-vivo

@xuchang-vivo xuchang-vivo commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Accept and retain SO_REUSEADDR as a compatibility option while preserving the current one-listener-per-endpoint behavior.
  • Match socket option identifiers exactly and validate option pointers and lengths.
  • Give every socket operation its own reply object instead of sharing reply state across calls.
  • Enforce SO_RCVTIMEO and SO_SNDTIMEO for blocking TCP, UDP, and ICMP send/receive operations.
  • Treat a zero timeout as clearing the option and reject invalid timeval values.

Motivation

Rust TcpListener::bind() enables SO_REUSEADDR before binding. BlueOS previously returned ENOPROTOOPT, so otherwise valid listeners failed before reaching bind().

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.

  • The network loop must claim a waiting operation before invoking its callback.
  • A timeout can cancel only a waiting operation.
  • If the network loop is executing a callback, the syscall waits until that execution completes or parks again.
  • Blocking socket paths return to the waiting state only after the callback has been transferred to a socket waker.
  • Cancelled queued or woken operations are dropped before their callbacks can run.

This prevents a timed-out syscall from returning while the network thread may still access the caller-owned send or receive buffer.

Related work

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.rs
  • git diff --check
  • No board build was run.

@xuchang-vivo

Copy link
Copy Markdown
Contributor Author

build_prs

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

✅ All jobs completed successfully, see https://github.com/vivoblueos/kernel/actions/runs/32960999069.

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.

1 participant