mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 15:50:13 +01:00
Server correct shutdown/force shutdown
This commit is contained in:
parent
21d53dabec
commit
c1e939f1e3
@ -22,8 +22,17 @@ public class Server : GlobalBase
|
|||||||
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/");
|
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/");
|
||||||
else
|
else
|
||||||
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/");
|
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/");
|
||||||
Thread t = new (Listen);
|
Thread listenThread = new (Listen);
|
||||||
t.Start();
|
listenThread.Start();
|
||||||
|
Thread watchThread = new(WatchRunning);
|
||||||
|
watchThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WatchRunning()
|
||||||
|
{
|
||||||
|
while(_parent.keepRunning)
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
this._listener.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Listen()
|
private void Listen()
|
||||||
@ -33,13 +42,20 @@ public class Server : GlobalBase
|
|||||||
Log($"Listening on {prefix}");
|
Log($"Listening on {prefix}");
|
||||||
while (this._listener.IsListening && _parent.keepRunning)
|
while (this._listener.IsListening && _parent.keepRunning)
|
||||||
{
|
{
|
||||||
HttpListenerContext context = this._listener.GetContextAsync().Result;
|
try
|
||||||
Log($"{context.Request.HttpMethod} {context.Request.Url} {context.Request.UserAgent}");
|
|
||||||
Task t = new(() =>
|
|
||||||
{
|
{
|
||||||
HandleRequest(context);
|
HttpListenerContext context = this._listener.GetContext();
|
||||||
});
|
Log($"{context.Request.HttpMethod} {context.Request.Url} {context.Request.UserAgent}");
|
||||||
t.Start();
|
Task t = new(() =>
|
||||||
|
{
|
||||||
|
HandleRequest(context);
|
||||||
|
});
|
||||||
|
t.Start();
|
||||||
|
}
|
||||||
|
catch (HttpListenerException e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user