Consolidate internal duplication#150
Merged
Merged
Conversation
No public header change, no wire change, net -116 lines: - netcode_server_process_packet builds the allowed packets table and timestamp, then delegates to netcode_server_read_and_process_packet instead of duplicating its ~45 line body. This was the pair where a fix applied to one had to be remembered in the other. - The client receive loops (socket and network simulator) feed packets through netcode_client_process_packet instead of inlining the same allowed packets table and netcode_read_packet call twice more. - netcode_address_to_sockaddr / netcode_sockaddr_to_address replace the IPv4/IPv6 sockaddr conversions repeated across socket create (bind and getsockname), send and receive. - netcode_send_packet_to_address unifies the simulator/override/socket dispatch repeated in the client send path and both server send paths. - netcode_server_reset_client_slot shares the packet queue drain and slot reset between normal and loopback client disconnect. Verified: 42/42 tests in Release, Debug, and ASan+UBSan; fuzz corpus and adversarial inputs replay clean under ASan; client_server example runs end to end over real sockets; 45 second ASan soak run churned 5,913 client connections through the refactored paths with zero findings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Games that care about allocation churn are expected to supply an allocator whose alloc and free are cheap and don't call out to the OS. That is how shipped games use this library: yojimbo provides its own allocator through these hooks. The library defines where allocations happen; the application decides how fast they are. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Removes the internal duplication flagged in CLAUDE.md — no public header change, no wire change, net −116 lines:
netcode_server_process_packetdelegates tonetcode_server_read_and_process_packetinstead of duplicating its ~45-line body (the pair where a fix to one had to be remembered in the other).netcode_client_process_packet— the public entry point — instead of inlining the allowed-packets table +netcode_read_packetcall in two more places.netcode_address_to_sockaddr/netcode_sockaddr_to_addressreplace the IPv4/IPv6 conversions repeated across socket create (bind + getsockname), send, and receive.netcode_send_packet_to_addressunifies the simulator/override/socket dispatch shared by the client send path and both server send paths.netcode_server_reset_client_slotshares queue drain + slot reset between normal and loopback disconnect.Only observable behavior difference: the client samples
time(NULL)per packet instead of per receive batch (whole-second token-expiry timestamp — no functional change).Verification
client_serverexample end-to-end over real sockets🤖 Generated with Claude Code