Browse Source

DnsForwarder: more aggressive error handle

HOME 8 months ago
parent
commit
62b7019833
2 changed files with 15 additions and 4 deletions
  1. 14 3
      DnsForwarder/Program.cs
  2. 1 1
      DnsForwarder/Properties/launchSettings.json

+ 14 - 3
DnsForwarder/Program.cs

@@ -62,9 +62,20 @@ namespace DnsForwarder
 
         private static void StartHandleRequest()
         {
-            var buf = new byte[1500];
-            EndPoint from = new IPEndPoint(IPAddress.Any, 0);
-            _listener.BeginReceiveFrom(buf, 0, buf.Length, SocketFlags.None, ref from, Callback, buf);
+            while (true)
+            {
+                try
+                {
+                    var buf = new byte[1500];
+                    EndPoint from = new IPEndPoint(IPAddress.Any, 0);
+                    _listener.BeginReceiveFrom(buf, 0, buf.Length, SocketFlags.None, ref from, Callback, buf);
+                    break;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e);
+                }
+            }
         }
 
         private static void Callback(IAsyncResult ar)

+ 1 - 1
DnsForwarder/Properties/launchSettings.json

@@ -2,7 +2,7 @@
   "profiles": {
     "DnsForwarder": {
       "commandName": "Project",
-      "commandLineArgs": "MySecureDnsServerInHosts 114.114.114.114 z:/accelerated-domains.china.conf.txt"
+      "commandLineArgs": "0.0.0.0 MySecureDnsServerInHosts 114.114.114.114 z:/accelerated-domains.china.conf.txt"
     }
   }
 }