Przeglądaj źródła

fix:代码修复

pigflower 4 godzin od teraz
rodzic
commit
34e01bca17

+ 4 - 40
server/src/server/OpenCards.Server.Common/Http/HttpServer.cs

@@ -70,31 +70,14 @@ namespace OpenCards.Server.Common.Http
         protected readonly Func<HttpListenerContext, Task> onHandle;
         public HttpServer(string listenerUriPrefix, IService service, Func<HttpListenerContext, Task> onHandle, Logger log = null)
         {
-            this.httpListener = new HttpListener();
-            try
-            {
-                //httpListener.TimeoutManager.EntityBody = TimeSpan.FromSeconds(30);
-                //httpListener.TimeoutManager.HeaderWait = TimeSpan.FromSeconds(30);
-                //调整
-                //httpListener.TimeoutManager.IdleConnection = TimeSpan.FromSeconds(30);
-                //httpListener.TimeoutManager.DrainEntityBody = TimeSpan.FromSeconds(30);
-                //httpListener.TimeoutManager.RequestQueue = TimeSpan.FromSeconds(30);
-
-                this.listenerUriPrefix = listenerUriPrefix;
-                this.httpListener = CreateHttpListener(); // 替换原来的 new HttpListener() + 配置
-                this.prefixPath = HttpUtils.ParsePrefixPath(listenerUriPrefix);
-            }
-            catch (Exception e)
-            {
-                service.log.Error(e);
-            }
-
-            this.httpListener.Prefixes.Add(listenerUriPrefix);
+            this.listenerUriPrefix = listenerUriPrefix;
             this.prefixPath = HttpUtils.ParsePrefixPath(listenerUriPrefix);
             this.service = service;
             this.log = log == null ? this.service.log : log;
             this.onHandle = onHandle;
 
+            this.httpListener = CreateHttpListener();
+
             ServerUtils.GlobalUpdate += CheckHttpServer;
         }
 
@@ -119,18 +102,12 @@ namespace OpenCards.Server.Common.Http
             if (_disposed) return;
             try
             {
-                if (IsListenerDisposed())
-                {
-                    RecreateHttpListener();
-                    return;
-                }
-
                 if (!this.httpListener.IsListening)
                 {
                     log.Info("CheckHttpServer 目前监听到httpListener暂停了");
                     lock (listenerLock)
                     {
-                        if (_disposed || IsListenerDisposed())
+                        if (_disposed)
                             return;
                         if (!httpListener.IsListening)
                         {
@@ -188,19 +165,6 @@ namespace OpenCards.Server.Common.Http
             }
         }
 
-        private bool IsListenerDisposed()
-        {
-            try
-            {
-                _ = httpListener.IsListening;
-                return false;
-            }
-            catch (ObjectDisposedException)
-            {
-                return true;
-            }
-        }
-
         public void Start()
         {
             this.httpListener.Start();