You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 23:56:30 +09:00
NetQueue.TryDequeue failure will now only throw in DEBUG
WaitMessage will now create a wait event object if needed
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Lidgren.Network
|
|||||||
|
|
||||||
private int m_listenPort;
|
private int m_listenPort;
|
||||||
private object m_tag;
|
private object m_tag;
|
||||||
|
private object m_messageReceivedEventCreationLock = new object();
|
||||||
|
|
||||||
internal readonly List<NetConnection> m_connections;
|
internal readonly List<NetConnection> m_connections;
|
||||||
private readonly Dictionary<IPEndPoint, NetConnection> m_connectionLookup;
|
private readonly Dictionary<IPEndPoint, NetConnection> m_connectionLookup;
|
||||||
@@ -36,7 +37,13 @@ namespace Lidgren.Network
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (m_messageReceivedEvent == null)
|
if (m_messageReceivedEvent == null)
|
||||||
m_messageReceivedEvent = new AutoResetEvent(false);
|
{
|
||||||
|
lock (m_messageReceivedEventCreationLock) // make sure we don't create more than one event object
|
||||||
|
{
|
||||||
|
if (m_messageReceivedEvent == null)
|
||||||
|
m_messageReceivedEvent = new AutoResetEvent(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
return m_messageReceivedEvent;
|
return m_messageReceivedEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,8 +181,8 @@ namespace Lidgren.Network
|
|||||||
var msg = ReadMessage();
|
var msg = ReadMessage();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
return msg; // no need to wait; we already have a message to deliver
|
return msg; // no need to wait; we already have a message to deliver
|
||||||
if (m_messageReceivedEvent != null)
|
var msgEvt = MessageReceivedEvent;
|
||||||
m_messageReceivedEvent.WaitOne(maxMillis);
|
msgEvt.WaitOne(maxMillis);
|
||||||
return ReadMessage();
|
return ReadMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,15 @@ namespace Lidgren.Network
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
throw;
|
||||||
|
#else
|
||||||
|
item = default(T);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_lock.ExitWriteLock();
|
m_lock.ExitWriteLock();
|
||||||
@@ -200,7 +209,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an item from the head of the queue, or returns default(T) if empty
|
/// Gets all items from the head of the queue, or returns number of items popped
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TryDrain(IList<T> addTo)
|
public int TryDrain(IList<T> addTo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,20 +42,17 @@ namespace UnitTests
|
|||||||
peer.Shutdown("bye");
|
peer.Shutdown("bye");
|
||||||
|
|
||||||
// read all message
|
// read all message
|
||||||
NetIncomingMessage inc;
|
NetIncomingMessage inc = peer.WaitMessage(5000);
|
||||||
while((inc = peer.ReadMessage()) != null)
|
switch(inc.MessageType)
|
||||||
{
|
{
|
||||||
switch(inc.MessageType)
|
case NetIncomingMessageType.DebugMessage:
|
||||||
{
|
case NetIncomingMessageType.VerboseDebugMessage:
|
||||||
case NetIncomingMessageType.DebugMessage:
|
case NetIncomingMessageType.WarningMessage:
|
||||||
case NetIncomingMessageType.VerboseDebugMessage:
|
case NetIncomingMessageType.ErrorMessage:
|
||||||
case NetIncomingMessageType.WarningMessage:
|
Console.WriteLine("Peer message: " + inc.ReadString());
|
||||||
case NetIncomingMessageType.ErrorMessage:
|
break;
|
||||||
Console.WriteLine("Peer message: " + inc.ReadString());
|
case NetIncomingMessageType.Error:
|
||||||
break;
|
throw new Exception("Received error message!");
|
||||||
case NetIncomingMessageType.Error:
|
|
||||||
throw new Exception("Received error message!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Done");
|
Console.WriteLine("Done");
|
||||||
|
|||||||
Reference in New Issue
Block a user