Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the actual purpose of ENET_PACKET_FLAG_SENT #259

Open
cher-nov opened this issue Jun 26, 2024 · 0 comments
Open

Clarify the actual purpose of ENET_PACKET_FLAG_SENT #259

cher-nov opened this issue Jun 26, 2024 · 0 comments

Comments

@cher-nov
Copy link

cher-nov commented Jun 26, 2024

It is currently not clear from the documentation that the sole purpose of ENET_PACKET_FLAG_SENT is to check for it in the designated packet->freeCallback function when releasing the packet. This is according directly to the next code:

enet/protocol.c

Lines 175 to 185 in a356ac0

if (outgoingCommand -> packet != NULL)
{
-- outgoingCommand -> packet -> referenceCount;
if (outgoingCommand -> packet -> referenceCount == 0)
{
outgoingCommand -> packet -> flags |= ENET_PACKET_FLAG_SENT;
enet_packet_destroy (outgoingCommand -> packet);
}
}

enet/protocol.c

Lines 267 to 280 in a356ac0

if (outgoingCommand -> packet != NULL)
{
if (wasSent)
peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength;
-- outgoingCommand -> packet -> referenceCount;
if (outgoingCommand -> packet -> referenceCount == 0)
{
outgoingCommand -> packet -> flags |= ENET_PACKET_FLAG_SENT;
enet_packet_destroy (outgoingCommand -> packet);
}
}

enet/packet.c

Lines 53 to 68 in a356ac0

/** Destroys the packet and deallocates its data.
@param packet packet to be destroyed
*/
void
enet_packet_destroy (ENetPacket * packet)
{
if (packet == NULL)
return;
if (packet -> freeCallback != NULL)
(* packet -> freeCallback) (packet);
if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) &&
packet -> data != NULL)
enet_free (packet -> data);
enet_free (packet);
}

Also, the name of the constant itself is somewhat ambiguous, since the documentation does not indicate whether it is set only upon a complete transfer of the packet (i.e. acknowledged delivery) or after any partial / failed / etc attempts.

The ability for the sender to check this flag on the packet is very useful, for example, in the case of transferring large files so as not to store them entirely in memory and not send explicit delivery confirmations in addition to the already existing library ones (and therefore redundant).

@cher-nov cher-nov changed the title Purpose of ENET_PACKET_FLAG_SENT Actual purpose of ENET_PACKET_FLAG_SENT Jun 26, 2024
@cher-nov cher-nov changed the title Actual purpose of ENET_PACKET_FLAG_SENT Clarify the actual purpose of ENET_PACKET_FLAG_SENT Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant