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

Update NetPeer.cs #48

Closed AgentFire closed 8 years ago

AgentFire commented 8 years ago

Fixed an issue in the WaitMessage(int) when MessageReceivedEvent is signaled, yet ReadMessage() returns null.

lidgren commented 8 years ago

I'll integrate; but not sure why WaitMessage would fire when there's no message, unless you're reading from many threads simultaneously (which is quite fine). Run in DEBUG to make sure there's no exception that's glossed over in RELEASE.

AgentFire commented 8 years ago

@lidgren The behaviour I observe takes place exactly in DEBUG mode. Never tried RELEASE tho.

However, I can describe what I do: the code runs at the server, and a client uses Connect to establish connection, then at the server I do successefully read the ConnectionApproval message, yet I ignore it, skipping any Deny or Approve method calls. That produces a Warning message (as expected tho). Yet what is not expected is that after I ignore that incoming connection, next message read by ReadMessage() is returned as null, while the AutoResetEvent is "set" (WaitOne returns true).

That happens again if you do all the same (ignore the incoming connection) in the same NetPeer without any restarts/resets.

lidgren commented 8 years ago

Ok, not sure why that happens. However, altho unexpected; ReadMessage() should be assumed to sometimes return null - it just means there's no message to read.