You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-18 16:16:35 +09:00
global mutex on bind added
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// remove all callbacks regardless of sync context
|
// remove all callbacks regardless of sync context
|
||||||
m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback));
|
m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback));
|
||||||
|
|
||||||
if (m_receiveCallbacks.Count < 1)
|
if (m_receiveCallbacks.Count < 1)
|
||||||
m_receiveCallbacks = null;
|
m_receiveCallbacks = null;
|
||||||
@@ -116,40 +116,41 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
m_lastSocketBind = now;
|
m_lastSocketBind = now;
|
||||||
|
|
||||||
if (m_socket == null)
|
using (var mutex = new Mutex(false, "Global\\lidgrenSocketBind"))
|
||||||
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
|
||||||
|
|
||||||
if (reBind)
|
|
||||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
|
|
||||||
|
|
||||||
m_socket.ReceiveBufferSize = m_configuration.ReceiveBufferSize;
|
|
||||||
m_socket.SendBufferSize = m_configuration.SendBufferSize;
|
|
||||||
m_socket.Blocking = false;
|
|
||||||
|
|
||||||
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port);
|
|
||||||
m_socket.Bind(ep);
|
|
||||||
|
|
||||||
// try catch only works on linux not osx
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// this is not supported in mono / mac or linux yet.
|
try
|
||||||
if(Environment.OSVersion.Platform != PlatformID.Unix)
|
|
||||||
{
|
{
|
||||||
const uint IOC_IN = 0x80000000;
|
mutex.WaitOne();
|
||||||
const uint IOC_VENDOR = 0x18000000;
|
|
||||||
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
|
if (m_socket == null)
|
||||||
m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
|
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||||
|
|
||||||
|
if (reBind)
|
||||||
|
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
|
||||||
|
|
||||||
|
m_socket.ReceiveBufferSize = m_configuration.ReceiveBufferSize;
|
||||||
|
m_socket.SendBufferSize = m_configuration.SendBufferSize;
|
||||||
|
m_socket.Blocking = false;
|
||||||
|
|
||||||
|
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port);
|
||||||
|
m_socket.Bind(ep);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const uint IOC_IN = 0x80000000;
|
||||||
|
const uint IOC_VENDOR = 0x18000000;
|
||||||
|
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
|
||||||
|
m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignore; SIO_UDP_CONNRESET not supported on this platform
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mutex.ReleaseMutex();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var boundEp = m_socket.LocalEndPoint as NetEndPoint;
|
var boundEp = m_socket.LocalEndPoint as NetEndPoint;
|
||||||
|
|||||||
Reference in New Issue
Block a user