mas-bandwidth / netcode

Secure client/server connections over UDP
BSD 3-Clause "New" or "Revised" License
2.43k stars 191 forks source link

What is the purpose of `netcode_server_process_packet`? #130

Closed dbechrd closed 2 months ago

dbechrd commented 2 months ago

I don't understand why the function netcode_server_process_packet exists. It's nearly identical to netcode_server_read_and_process_packet, with the exception of setting an allowed_packets filter, but netcode_server_read_and_process_packet is always called from inside of netcode_server_receive_packets, which sets the same filter.

It is not used in any of the tests or examples, neither in this repository, nor in yojimbo, but it is exposed in the header as part of netcode's public interface.

Does this function have a use-case? Why would the user ever want to receive one packet at a time?

\ netcode_server_process_packet, whose purpose I do not understand: https://github.com/mas-bandwidth/netcode/blob/efd0c6d64e21dc501be3d589f25b3a54e2e66e95/netcode.c#L4578

\ netcode_server_process_packet, exposed in the header: https://github.com/mas-bandwidth/netcode/blob/efd0c6d64e21dc501be3d589f25b3a54e2e66e95/netcode.h#L247

\ netcode_server_read_and_process_packet which is part of the internal implementation of netcode_server_receive_packets: https://github.com/mas-bandwidth/netcode/blob/efd0c6d64e21dc501be3d589f25b3a54e2e66e95/netcode.c#L4632

\ netcode_server_receive_packets: https://github.com/mas-bandwidth/netcode/blob/efd0c6d64e21dc501be3d589f25b3a54e2e66e95/netcode.c#L4687

gafferongames commented 2 months ago

It's a public interface to allow higher level libraries to directly inject packets from memory into the protocol, to support some higher level functionality in Yojimbo. It's not used directly by netcode, but by other libraries that use netcode -- for example, when somebody wants to replace the netcode socket implementation with their own.