diff --git a/Lidgren.Network/NetPeer.Send.cs b/Lidgren.Network/NetPeer.Send.cs index d8fdf3f..ffbad45 100644 --- a/Lidgren.Network/NetPeer.Send.cs +++ b/Lidgren.Network/NetPeer.Send.cs @@ -45,6 +45,8 @@ namespace Lidgren.Network if (msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); + msg.m_isSent = true; + int len = msg.LengthBytes; if (len <= recipient.m_currentMTU) { @@ -91,6 +93,8 @@ namespace Lidgren.Network int mtu = GetMTU(recipients); + msg.m_isSent = true; + int len = msg.LengthBytes; if (len <= m_configuration.MaximumTransmissionUnit) { @@ -158,6 +162,7 @@ namespace Lidgren.Network throw new NetException("Unconnected messages too long! Must be shorter than NetConfiguration.MaximumTransmissionUnit (currently " + m_configuration.MaximumTransmissionUnit + ")"); msg.m_messageType = NetMessageType.Unconnected; + msg.m_isSent = true; Interlocked.Increment(ref msg.m_recyclingCount); m_unsentUnconnectedMessages.Enqueue(new NetTuple(recipient, msg)); @@ -178,6 +183,7 @@ namespace Lidgren.Network throw new NetException("Unconnected messages too long! Must be shorter than NetConfiguration.MaximumTransmissionUnit (currently " + m_configuration.MaximumTransmissionUnit + ")"); msg.m_messageType = NetMessageType.Unconnected; + msg.m_isSent = true; Interlocked.Add(ref msg.m_recyclingCount, recipients.Count); foreach(IPEndPoint ep in recipients) diff --git a/UnitTests/Program.cs b/UnitTests/Program.cs index 5070f88..47a1936 100644 --- a/UnitTests/Program.cs +++ b/UnitTests/Program.cs @@ -27,6 +27,18 @@ namespace UnitTests EncryptionTests.Run(peer); + var om = peer.CreateMessage(); + peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242)); + try + { + peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242)); + } + catch (NetException nex) + { + if (nex.Message != "This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently") + throw nex; + } + peer.Shutdown("bye"); // read all message