Skip to content

Conversation

@klaaspieter
Copy link
Contributor

Motivation:

NIO supports ECN, packet info, and segmentation metadata but not timestamps. Userspace timestamps are imprecise due to scheduler latency between packet arrival and recvmsg. SO_TIMESTAMP captures the exact kernel receive time with microsecond precision via control messages, which is critical for accurate RTT measurements and latency monitoring.

Modifications:

  • Add timestamp field to AddressedEnvelope.Metadata
  • Add TimestampOption channel option
  • Parse SCM_TIMESTAMP control messages in ControlMessageParser
  • Add init(ecnState:packetInfo:segmentSize:timestamp:) to Metadata
  • Add test coverage

Result:

Datagram channels can enable .receiveTimestamp to receive kernel timestamps in AddressedEnvelope.Metadata.timestamp as a Double (seconds since epoch with microsecond precision).

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Thanks for this patch! This mostly looks really good, I've left a few notes in the diff.

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Jan 9, 2026
@klaaspieter
Copy link
Contributor Author

@Lukasa the API breaking change made sense because I changed a constructor. What is the best way to handle this? I can add a new constructor with the new argument, keeping the old one unchanged. I can also make the default value for timestamp be nil.

@glbrntt
Copy link
Contributor

glbrntt commented Feb 5, 2026

@Lukasa the API breaking change made sense because I changed a constructor. What is the best way to handle this? I can add a new constructor with the new argument, keeping the old one unchanged. I can also make the default value for timestamp be nil.

You'll need to add a new init and keep the old one unchanged. Adding a default value to an existing function is actually an API break.

Motivation:

NIO supports ECN, packet info, and segmentation metadata but not timestamps. Userspace timestamps are imprecise due to scheduler latency between packet arrival and recvmsg. SO_TIMESTAMP captures the exact kernel receive time with microsecond precision via control messages, which is critical for accurate RTT measurements and latency monitoring.

Modifications:

- Add timestamp field to AddressedEnvelope.Metadata
- Add TimestampOption channel option
- Parse SCM_TIMESTAMP control messages in ControlMessageParser
- Add init(ecnState:packetInfo:segmentSize:timestamp:) to Metadata
- Add test coverage

Result:

Datagram channels can enable .receiveTimestamp to receive kernel timestamps in AddressedEnvelope.Metadata.timestamp as a Double (seconds since epoch with microsecond precision).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants