willardf / Hazel-Networking

Hazel Networking is a low level networking library for C# providing connection-oriented, message-based communication via RUDP.
MIT License
385 stars 60 forks source link

Breaking Change: Fixed torn packets by requiring users to not recycle NewConnection messages. #33

Closed willardf closed 2 years ago

willardf commented 2 years ago

Prior to this PR, you can spam a ConnectionListener with connection messages (but no follow up data, just connect and disconnect) and eventually you will get callbacks on DataReceived. The data received can look like 0's, connect, disconnect, or torn messages suggesting a double recycle or usage after recycle.

The issue is that NewConnection messages are expected to be recycled by the user but we require data in the message afterwards. Ideally we would not use the message data after a callback, but in order to ensure very low latency connections can complete the NewConnection callback fully before receiving subsequent data, we have to ack the packet afterwards.

I believe that this is the most elegant solution and while it is a changed expectation for users, I don't think it will be challenging for many to meet. The NewConnection message seems unlikely to be a long-lived message as it is in-principle intended to provide an early accept/reject mechanism and/or serialized context for the test of the communications.