1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-17 23:56:30 +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

@@ -1,24 +1,22 @@
<Properties StartupConfiguration="{6691874A-1766-4A08-A72A-B1132FAB8E58}|Default"> <Properties StartupConfiguration="{6691874A-1766-4A08-A72A-B1132FAB8E58}|Default">
<MonoDevelop.Ide.Workbench ActiveDocument="Lidgren.Network/NetQueue.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="Lidgren.Network/NetPeer.Internal.cs">
<Files> <Files>
<File FileName="UnitTests/Program.cs" Line="15" Column="1" /> <File FileName="UnitTests/Program.cs" Line="12" Column="1" />
<File FileName="Lidgren.Network/NetNatIntroduction.cs" Line="12" Column="27" /> <File FileName="Lidgren.Network/NetNatIntroduction.cs" Line="12" Column="27" />
<File FileName="Lidgren.Network/NetPeer.cs" Line="120" Column="1" /> <File FileName="Lidgren.Network/NetPeer.Internal.cs" Line="138" Column="37" />
<File FileName="Lidgren.Network/NetPeer.Internal.cs" Line="27" Column="1" />
<File FileName="Lidgren.Network/NetPeerConfiguration.cs" Line="130" Column="1" /> <File FileName="Lidgren.Network/NetPeerConfiguration.cs" Line="130" Column="1" />
<File FileName="Lidgren.Network/NetPeer.LatencySimulation.cs" Line="38" Column="1" /> <File FileName="Lidgren.Network/NetPeer.LatencySimulation.cs" Line="38" Column="1" />
<File FileName="Lidgren.Network/NetPeerStatistics.cs" Line="53" Column="1" /> <File FileName="Lidgren.Network/NetPeerStatistics.cs" Line="53" Column="1" />
<File FileName="Lidgren.Network/NetQueue.cs" Line="86" Column="1" /> <File FileName="Lidgren.Network/NetQueue.cs" Line="89" Column="1" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore> <BreakpointStore />
<Breakpoint file="/Users/user/lidgren-network-gen3/UnitTests/Program.cs" relfile="UnitTests/Program.cs" line="12" column="4" />
<Breakpoint file="/Users/user/lidgren-network-gen3/Lidgren.Network/NetPeer.Internal.cs" relfile="Lidgren.Network/NetPeer.Internal.cs" line="111" column="1" />
</BreakpointStore>
</MonoDevelop.Ide.DebuggingService.Breakpoints> </MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches /> <MonoDevelop.Ide.DebuggingService.PinnedWatches>
<Watch file="Lidgren.Network/NetPeer.Internal.cs" line="136" offsetX="581" offsetY="2025" expression="Environment.OSVersion.Platform" liveUpdate="False" />
</MonoDevelop.Ide.DebuggingService.PinnedWatches>
<MultiItemStartupConfigurations /> <MultiItemStartupConfigurations />
<MonoDevelop.Ide.ItemProperties.UnitTests PreferredExecutionTarget="MonoDevelop.Default" /> <MonoDevelop.Ide.ItemProperties.UnitTests PreferredExecutionTarget="MonoDevelop.Default" />
</Properties> </Properties>

View File

@@ -34,7 +34,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;__CONSTRAINED__</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>

View File

@@ -4,12 +4,12 @@ using System.Threading;
using System.Diagnostics; using System.Diagnostics;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Net.Sockets; using System.Net.Sockets;
using System.Collections.Generic; using System.Collections.Generic;
#if !__NOIPENDPOINT__ #if !__NOIPENDPOINT__
using NetEndPoint = System.Net.IPEndPoint; using NetEndPoint = System.Net.IPEndPoint;
#endif #endif
namespace Lidgren.Network namespace Lidgren.Network
{ {
public partial class NetPeer public partial class NetPeer
@@ -39,13 +39,13 @@ namespace Lidgren.Network
internal bool m_executeFlushSendQueue; internal bool m_executeFlushSendQueue;
private AutoResetEvent m_messageReceivedEvent; private AutoResetEvent m_messageReceivedEvent;
private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks; private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks;
/// <summary> /// <summary>
/// Gets the socket, if Start() has been called /// Gets the socket, if Start() has been called
/// </summary> /// </summary>
public Socket Socket { get { return m_socket; } } public Socket Socket { get { return m_socket; } }
/// <summary> /// <summary>
/// Call this to register a callback for when a new message arrives /// Call this to register a callback for when a new message arrives
/// </summary> /// </summary>
@@ -58,18 +58,18 @@ namespace Lidgren.Network
if (m_receiveCallbacks == null) if (m_receiveCallbacks == null)
m_receiveCallbacks = new List<NetTuple<SynchronizationContext, SendOrPostCallback>>(); m_receiveCallbacks = new List<NetTuple<SynchronizationContext, SendOrPostCallback>>();
m_receiveCallbacks.Add(new NetTuple<SynchronizationContext, SendOrPostCallback>(syncContext, callback)); m_receiveCallbacks.Add(new NetTuple<SynchronizationContext, SendOrPostCallback>(syncContext, callback));
} }
/// <summary> /// <summary>
/// Call this to unregister a callback, but remember to do it in the same synchronization context! /// Call this to unregister a callback, but remember to do it in the same synchronization context!
/// </summary> /// </summary>
public void UnregisterReceivedCallback(SendOrPostCallback callback) public void UnregisterReceivedCallback(SendOrPostCallback callback)
{ {
if (m_receiveCallbacks == null) if (m_receiveCallbacks == null)
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;
@@ -112,7 +112,7 @@ namespace Lidgren.Network
if (now - m_lastSocketBind < 1.0) if (now - m_lastSocketBind < 1.0)
{ {
LogDebug("Suppressed socket rebind; last bound " + (now - m_lastSocketBind) + " seconds ago"); 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; m_lastSocketBind = now;
@@ -127,17 +127,23 @@ namespace Lidgren.Network
m_socket.Blocking = false; m_socket.Blocking = false;
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
{ {
//const uint IOC_IN = 0x80000000; // this is not supported in mono / mac or linux yet.
//const uint IOC_VENDOR = 0x18000000; if(Environment.OSVersion.Platform != PlatformID.Unix)
//uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; {
//m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null); 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 // ignore; SIO_UDP_CONNRESET not supported on this platform
} }

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> <Platform Condition=" '$(Platform)' == '' ">x86</Platform>