[ENet-discuss] packet->referenceCount greater than zero

Lee Salzman lsalzman1 at cox.net
Tue Mar 18 20:08:13 PDT 2008


In practice, no. The only time that function ever fails is if you try to 
send a packet to a peer that
is not in the connected state, or you send a packet on a non-existent 
channel. Both are essentially
user errors in the sense that if you use the library properly, should 
never happen.

The reason that enet_peer_send() does not destroy the packet in this 
case is if you want to send
a packet to multiple peers, destroying the packet in said case just 
because it has a 0 reference count
would nuke the packet before you had a chance to send it out to other peers.

Functions like enet_host_broadcast(), on the other hand, implicitly 
destroy the packet if it failed to send
to any peer.

Lee

Marc Rochel wrote:
> Hi !
>
> Now I'm surprised. I never did that before. Do we have to add that line
>
> if (! packet -> referenceCount) enet_packet_destroy (packet);
>
> always after 
>
> enet_peer_send (..., packet);
>
> ? I always just did the enet_peer_send and nothing more.
>
> Best regards
>   Marc
>  
>
> -----Ursprüngliche Nachricht-----
> Von: enet-discuss-bounces at cubik.org [mailto:enet-discuss-bounces at cubik.org]
> Im Auftrag von Lee Salzman
> Gesendet: Dienstag, 18. März 2008 23:58
> An: Discussion of the ENet library
> Betreff: Re: [ENet-discuss] packet->referenceCount greater than zero
>
> enet_peer_send (..., packet);
> if (! packet -> referenceCount) enet_packet_destroy (packet);
>
> Doug Kimzey wrote:
>   
>> Hello,
>>
>> I have been troubleshooting a memory leak in my application that uses 
>> eNet. I suspect that we need to do some cleanup on sent packets but 
>> would like some guidance – (so please correct me where I am wrong).
>>
>> · Packets are usually only destroyed when the 
>> _ENetPacket::referenceCount field is equal to 0
>>
>> · In walking through my code:
>>
>> o A packet is successfully created – and the newly created packet has 
>> a referenceCount of 0
>>
>> o ::enet_peer_send(…) queues the packet fragments when the packet size 
>> exceeds the fragment length. For each fragment in the packet,
>> ::enet_peer_queue_outgoing_command(…) is called.
>>
>> o In ::enet_peer_queue_outgoing_command(…):
>>
>> · An ENetOutgoingCommand is allocated and initialized
>>
>> · The packet->referenceCount is incremented.
>>
>> o ::enet_peer_send returns 0 (success)
>>
>> o My packet->referenceCount is greater than 0 – so my call to
>> ::enet_packet_destroy(…) is not made and the packet memory is not freed.
>>
>> Is there an enet function that should be called after ::enet_peer_send 
>> that will verify the packet was indeed sent and decrement the
>> packet->referenceCount before calling ::enet_packet_destroy?
>>
>> Thank you,
>>
>> Doug Kimzey
>>
>> Doug.kimzey at dpra.com
>>
>> DPRA, Inc.
>>
>> ----------------------------------------------------------------------
>> --
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>   
>>     
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>   



More information about the ENet-discuss mailing list