1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

disable socket.IOControl(SIO_UDP_CONNECT) on unix but not windows

This commit is contained in:
RevoluPowered
2017-11-10 14:51:48 +00:00
parent 4c81cf3c03
commit 9e5525711e
4 changed files with 39 additions and 35 deletions

View File

@@ -4,12 +4,12 @@ using System.Threading;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Collections.Generic;
#if !__NOIPENDPOINT__
using NetEndPoint = System.Net.IPEndPoint;
using NetEndPoint = System.Net.IPEndPoint;
#endif
namespace Lidgren.Network
{
public partial class NetPeer
@@ -39,13 +39,13 @@ namespace Lidgren.Network
internal bool m_executeFlushSendQueue;
private AutoResetEvent m_messageReceivedEvent;
private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks;
private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks;
/// <summary>
/// Gets the socket, if Start() has been called
/// </summary>
public Socket Socket { get { return m_socket; } }
public Socket Socket { get { return m_socket; } }
/// <summary>
/// Call this to register a callback for when a new message arrives
/// </summary>
@@ -58,18 +58,18 @@ namespace Lidgren.Network
if (m_receiveCallbacks == null)
m_receiveCallbacks = new List<NetTuple<SynchronizationContext, SendOrPostCallback>>();
m_receiveCallbacks.Add(new NetTuple<SynchronizationContext, SendOrPostCallback>(syncContext, callback));
}
}
/// <summary>
/// Call this to unregister a callback, but remember to do it in the same synchronization context!
/// </summary>
public void UnregisterReceivedCallback(SendOrPostCallback callback)
{
if (m_receiveCallbacks == null)
return;
// remove all callbacks regardless of sync context
m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback));
return;
// remove all callbacks regardless of sync context
m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback));
if (m_receiveCallbacks.Count < 1)
m_receiveCallbacks = null;
@@ -112,7 +112,7 @@ namespace Lidgren.Network
if (now - m_lastSocketBind < 1.0)
{
LogDebug("Suppressed socket rebind; last bound " + (now - m_lastSocketBind) + " seconds ago");
return; // only allow rebind once every second
return; // only allow rebind once every second
}
m_lastSocketBind = now;
@@ -127,17 +127,23 @@ namespace Lidgren.Network
m_socket.Blocking = false;
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
{
//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);
{
// this is not supported in mono / mac or linux yet.
if(Environment.OSVersion.Platform != PlatformID.Unix)
{
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
catch (System.Exception e)
{
// this will be thrown on linux but not mac if it doesn't exist.
// ignore; SIO_UDP_CONNRESET not supported on this platform
}