|
@@ -11,13 +11,15 @@ using System.Web;
|
|
|
|
|
|
namespace Wv2h
|
|
|
{
|
|
|
- public class Wv2hModule : IHttpModule
|
|
|
+ public class Wv2hModule : IHttpModule, IDisposable
|
|
|
{
|
|
|
private static object _lock = new object();
|
|
|
|
|
|
private static Process _process;
|
|
|
private static IPEndPoint _listening;
|
|
|
|
|
|
+ //TODO: Use pid.lock to hold process
|
|
|
+
|
|
|
private static void Log(string info)
|
|
|
{
|
|
|
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "logs.log"), DateTime.Now + " " + info + Environment.NewLine);
|
|
@@ -40,6 +42,15 @@ namespace Wv2h
|
|
|
{
|
|
|
if (_process == null || _process?.HasExited == true)
|
|
|
{
|
|
|
+ if (_process == null)
|
|
|
+ {
|
|
|
+ Log("Init process");
|
|
|
+ }
|
|
|
+ else if (_process?.HasExited == true)
|
|
|
+ {
|
|
|
+ Log("Last Process Exit. Start new process");
|
|
|
+ }
|
|
|
+
|
|
|
_process = new Process
|
|
|
{
|
|
|
StartInfo = {
|
|
@@ -50,7 +61,6 @@ namespace Wv2h
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- Log("Pending start process");
|
|
|
_process.Start();
|
|
|
var pid = _process.Id;
|
|
|
Log("Process started, Pid:" + pid);
|
|
@@ -70,8 +80,13 @@ namespace Wv2h
|
|
|
//forward ws to v2
|
|
|
context.PostMapRequestHandler += delegate
|
|
|
{
|
|
|
+ var ctx = HttpContext.Current;
|
|
|
+ var req = HttpContext.Current.Request;
|
|
|
+
|
|
|
+ Log($"{(ctx.IsWebSocketRequest ? "[WS]" : "")} {req.UserHostAddress} {req.HttpMethod} {req.Path} ");
|
|
|
+
|
|
|
WebSocketForwardModule.ForwardCurrentContext(
|
|
|
- ConfigurationManager.AppSettings["key"],
|
|
|
+ ConfigurationManager.AppSettings["key"],
|
|
|
ConfigurationManager.AppSettings["value"],
|
|
|
_listening, 1024 * int.Parse(ConfigurationManager.AppSettings["bsk"]));
|
|
|
};
|