mas-bandwidth / netcode

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

Wait upon certain time for incoming packets #116

Closed kienhg96 closed 10 months ago

kienhg96 commented 10 months ago

Hi, it's me again.

I discovered that in ENet, the functionenet_host_service which takes the last argument timeout to wait for the next incoming packets. https://github.com/lsalzman/enet/blob/master/protocol.c#L1788 AFAIK, it uses select function.

This is very useful if we run the network polling/pushing in non-main thread. This makes the engine sends and receives the packets as soon as posible.

This can be done by adding timeout to netcode_server_update and netcode_client_update. If the timeout is zero, two update functions run non-blocking and otherwise.

Thanks for considering.

gafferongames commented 10 months ago

If you can create a PR for this, I'd be happy to review it. Thanks!