[ENet-discuss] Question aboutenet_host_connect/enet_peer_disconnect data
Thorbjørn Lindeijer
bjorn at lindeijer.nl
Mon Mar 18 19:45:09 UTC 2024
On Mon, Mar 18, 2024, at 19:53, Martin Man wrote:
> When you enet_host_connect to another peer and pass in the data
> parameter of X… that constant X gets passed to the remote event
> ENET_EVENT_TYPE_CONNECT as expected. However on the local host where
> the connect originated, the ENET_EVENT_TYPE_CONNECT receives 0.
>
> Similarly, when you enet_peer_disconnect with custom data value X, that
> value X gets transmitted to the remote side and propagated up via
> ENET_EVENT_TYPE_DISCONNECT, but originating host receives the event
> with 0.
>
> I am just wondering what is the thinking behind this feature. I have
> gotten the feeling that the same X passed to _connect and _disconnect
> should be propagated on both sides…
The data parameter is documented as follows: "user data supplied to the receiving host". So at least it appears to be working as documented.
With the current behavior for the ENET_EVENT_TYPE_CONNECT and ENET_EVENT_TYPE_DISCONNECT events, we can rely on "data" always being whatever the remote host has sent us when connecting / disconnecting, or 0 when it didn't send anything. That's different from having to handle a "data" value that could have originated either from the remote host or from the local host.
Also, ENet already provides a mechanism for sharing data locally, it being the data pointer in the ENetPeer structure. So if you need your connect / disconnect data locally, you could store it in the custom peer data instead.
I hope this helps. :-)
Cheers,
Thorbjørn
More information about the ENet-discuss
mailing list