Implemented socket state capturing#49
Conversation
|
Thanks so much Anton, this is a nice addition. I'd love to have comprehensive tests about some, if not all, the possible states. |
Introduces a `SocketState` enum covering all standard TCP connection states (Established, Listen, SynSent, SynReceived, FinWait1, FinWait2, TimeWait, Closed, CloseWait, LastAck, Closing), plus Unknown for UDP or unrecognized raw values. Each platform decodes the kernel's raw state integer into SocketState: - Linux: parses the hex state column from /proc/net/tcp and /proc/net/tcp6 - Windows: maps MIB_TCP_STATE integer constants - macOS/BSD: maps BSD kernel socket state integers The `state` field is added to the public `Listener` struct and included in its `Display` output. Integration tests cover Listen and Established states for both IPv4 and IPv6, CloseWait (verified by reading until EOF on the accepted socket before sampling), and UDP state.
I added the following integration tests for the
I couldn't come up with a reliable way to test the remaining states ( |
|
@GyulyVGC Hey! Just wondering if you have an ETA for merging this PR 🙂 |
|
Hey @Jamba777 thanks for your interest in this feature I'm pretty busy this period but I'll try my best to merge this and publish a new version in June |
Add socket state to Listener
Exposes the TCP connection state (e.g. LISTEN, ESTABLISHED, TIME_WAIT) as a new state: SocketState field on the Listener struct, available on all supported platforms.
What changed
Breaking change
Listener gains a new state field — callers constructing Listener directly (e.g. in tests) must now supply a SocketState. Integration test updated
accordingly.