RevenantX / LiteNetLib

Lite reliable UDP library for Mono and .NET
https://revenantx.github.io/LiteNetLib/index.html
MIT License
3k stars 489 forks source link

DontFragment unsupported SocketOption #268

Closed SynergiAios closed 5 years ago

SynergiAios commented 5 years ago

I have an simple issue, I wanted to give the netstandard 2.0 Version of LiteNetLib a try, but I got an instant issue when starting.

Error:

System.Net.Sockets.SocketException (45): Operation not supported
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue, Boolean silent)
   at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)
   at System.Net.Sockets.Socket.set_DontFragment(Boolean value)
   at LiteNetLib.NetSocket.Bind(IPAddress addressIPv4, IPAddress addressIPv6, Int32 port, Boolean reuseAddress) in E:\Projects\LiteNetLib\LiteNetLib\NetSocket.cs:line 105
   at LiteNetLib.NetManager.Start(IPAddress addressIPv4, IPAddress addressIPv6, Int32 port) in E:\Projects\LiteNetLib\LiteNetLib\NetManager.cs:line 821
   at LiteNetLib.NetManager.Start(Int32 port) in E:\Projects\LiteNetLib\LiteNetLib\NetManager.cs:line 848
_netManager.Start();

Library version: 0.8.1.1-beta

Framework: dotnetStandard 2.0, dotnet Core 2.1

OS: MacOs

SynergiAios commented 5 years ago

To be quite honest, I don't understand why this exception even raises. Checking your code, you have a try catch around it.

            if (socket.AddressFamily == AddressFamily.InterNetwork)
            {
                socket.Ttl = NetConstants.SocketTTL;

                try { socket.DontFragment = true; }
                catch (SocketException e)
                {
                    NetUtils.DebugWriteError("[B]DontFragment error: {0}", e.SocketErrorCode);
                }

                try { socket.EnableBroadcast = true; }
                catch (SocketException e)
                {
                    NetUtils.DebugWriteError("[B]Broadcast error: {0}", e.SocketErrorCode);
                }
            }
SynergiAios commented 5 years ago

Further Investigations, using the current nuget package 0.8.1.1-beta, this issue occurs. Using the current version of the repo and using a project reference and not a nuget package, the behaviour is as expected. The try-catch block triggers and puts into the logger, that the dontFragment is not supported. It doesn't crash any further and keeps running. Any Idea on this strange behaviour?

RevenantX commented 5 years ago

@SynergiAios seems that this is some specific ios/netcore bug.

RevenantX commented 5 years ago

@SynergiAios fixed

SynergiAios commented 5 years ago

@RevenantX just saw it, thx awesome.

SynergiAios commented 5 years ago

It so sad, written in Net Standard, and still have to insert special rules for MacOS. Whom to blame here would be interesting for me :) (Apple or Microsoft?)

RevenantX commented 5 years ago

@SynergiAios i think both)