lidgren / lidgren-network-gen3

Lidgren Network Library
https://groups.google.com/forum/#!forum/lidgren-network-gen3
MIT License
1.19k stars 331 forks source link

Fixed an issue #132 #133

Closed aienabled closed 4 years ago

aienabled commented 4 years ago

The issue report is here https://github.com/lidgren/lidgren-network-gen3/issues/132# NetPeer.Heartbeat() method will no longer prematurely return in case of encountering an incorrect packet.

Alas, Github showing a incredibly large diff. The actual changes are as minimal as possible:

  1. the inner body of the loop do { ... } while (m_socket.Available > 0); extracted into a new private method (ReceiveSocketData).

  2. the try-catch block around m_socket.ReceiveFrom(...) call moved outside the do { ... } while (m_socket.Available > 0); loop.

This way any socket exceptions will break the loop and properly handled (as expected). Meanwhile the return; calls from the inner loop are no longer return from the whole Heartbeat() method as they will only return from the method ReceiveSocketData called in the loop.

Regards!

lidgren commented 4 years ago

Man, I wish github would support real diff tools.

lidgren commented 4 years ago

Thanks for the fix!