lsalzman / enet

ENet reliable UDP networking library
MIT License
2.71k stars 669 forks source link

Are packets compressed once? #193

Closed playingoDEERUX closed 2 years ago

playingoDEERUX commented 2 years ago

Hello, I want to ask an important question about enet's range coder / compression. Does ENet only compress packets on enet_packet_create, or on every packet flush within enet_host_service which holds the queued packets using enet_peer_send, and does it compress for every peer packets are being sent to?

Thanks in regards, I hope the question is easy to understand as it would concern the effiency of ENet.

bjorn commented 2 years ago

Does ENet only compress packets on enet_packet_create, or on every packet flush within enet_host_service which holds the queued packets using enet_peer_send

So, compression happens in enet_protocol_send_outgoing_commands:

https://github.com/lsalzman/enet/blob/cf735e639e5c9e3d2d84d71f1dbf789e8c2f3fd0/protocol.c#L1653-L1658

Since it happens after calling enet_protocol_check_outgoing_commands, it seems to me like it first sets up all the buffers for sending, then compresses and then sends with enet_socket_send. That would imply, that when a reliable packet needs to be sent again, its data will also be compressed again.

and does it compress for every peer packets are being sent to?

Looks like it to me, but I'd suggest to try following the code yourself as well. :-)