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

global mutex on bind added

This commit is contained in:
lidgren
2018-10-20 10:53:23 +02:00
committed by GitHub
parent e26203f652
commit f9a56e4325

View File

@@ -116,6 +116,12 @@ namespace Lidgren.Network
} }
m_lastSocketBind = now; m_lastSocketBind = now;
using (var mutex = new Mutex(false, "Global\\lidgrenSocketBind"))
{
try
{
mutex.WaitOne();
if (m_socket == null) if (m_socket == null)
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
@@ -129,28 +135,23 @@ namespace Lidgren.Network
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port); var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port);
m_socket.Bind(ep); m_socket.Bind(ep);
// try catch only works on linux not osx
try try
{
// this is not supported in mono / mac or linux yet.
if(Environment.OSVersion.Platform != PlatformID.Unix)
{ {
const uint IOC_IN = 0x80000000; const uint IOC_IN = 0x80000000;
const uint IOC_VENDOR = 0x18000000; const uint IOC_VENDOR = 0x18000000;
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null); m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
} }
else catch
{ {
LogDebug("Platform doesn't support SIO_UDP_CONNRESET");
}
}
catch (System.Exception e)
{
LogDebug("Platform doesn't support SIO_UDP_CONNRESET");
// this will be thrown on linux but not mac if it doesn't exist.
// ignore; SIO_UDP_CONNRESET not supported on this platform // ignore; SIO_UDP_CONNRESET not supported on this platform
} }
}
finally
{
mutex.ReleaseMutex();
}
}
var boundEp = m_socket.LocalEndPoint as NetEndPoint; var boundEp = m_socket.LocalEndPoint as NetEndPoint;
LogDebug("Socket bound to " + boundEp + ": " + m_socket.IsBound); LogDebug("Socket bound to " + boundEp + ": " + m_socket.IsBound);