1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Update NetPeer.cs

Fixed an issue in the `WaitMessage(int)` when `MessageReceivedEvent` is signaled, yet `ReadMessage()` returns null.
This commit is contained in:
AgentFire
2015-10-05 16:33:46 +03:00
parent af0b32e93d
commit f9053998cd

View File

@@ -182,12 +182,21 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public NetIncomingMessage WaitMessage(int maxMillis) public NetIncomingMessage WaitMessage(int maxMillis)
{ {
var msg = ReadMessage(); NetIncomingMessage msg = ReadMessage();
if (msg != null)
return msg; // no need to wait; we already have a message to deliver while (msg == null)
var msgEvt = MessageReceivedEvent; {
msgEvt.WaitOne(maxMillis); // This could return true...
return ReadMessage(); if (!MessageReceivedEvent.WaitOne(maxMillis))
{
return null;
}
// ... while this will still returns null. That's why we need to cycle.
msg = ReadMessage();
}
return msg;
} }
/// <summary> /// <summary>