public void Open() { var ct = ContentTypes.TEXT_UTF8; var a = HeaderTypeFactory.Find("Content-Length"); AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler; HttpPacket hp = new HttpPacket(this, this); var gtmdate = GMTDate.Default; mServer = SocketFactory.CreateTcpServer(this, hp) .Setting(o => { o.SyncAccept = Options.SyncAccept; o.IOQueues = Options.IOQueues; o.DefaultListen.Host = Options.Host; o.IOQueueEnabled = Options.IOQueueEnabled; o.DefaultListen.Port = Options.Port; o.BufferSize = Options.BufferSize; o.LogLevel = Options.LogLevel; o.Combined = Options.PacketCombined; o.SessionTimeOut = Options.SessionTimeOut; o.UseIPv6 = Options.UseIPv6; o.BufferPoolMaxMemory = Options.BufferPoolMaxMemory; o.LittleEndian = false; o.Statistical = Options.Statistical; }); if (Options.SSL) { mServer.Setting(o => { o.AddListenSSL(Options.CertificateFile, Options.CertificatePassword, o.DefaultListen.Host, Options.SSLPort); }); } Name = "BeetleX Http Server"; if (mAssemblies != null) { foreach (System.Reflection.Assembly assembly in mAssemblies) { mResourceCenter.LoadManifestResource(assembly); } } mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly); mResourceCenter.Path = Options.StaticResourcePath; mResourceCenter.Debug = Options.Debug; mResourceCenter.Load(); ModuleManager.Load(); if (Options.ManageApiEnabled) { ServerController serverStatusController = new ServerController(); mActionFactory.Register(serverStatusController); } StartTime = DateTime.Now; mServer.Open(); mServerCounter = new ServerCounter(this); mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase; mUrlRewrite.AddRegion(this.Options.Routes); HeaderTypeFactory.Find(HeaderTypeFactory.HOST); AppDomain.CurrentDomain.UnhandledException += (s, e) => { using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt")) { Exception error = e.ExceptionObject as Exception; writer.WriteLine(DateTime.Now); if (error != null) { writer.WriteLine(error.Message); writer.WriteLine(error.StackTrace); if (error.InnerException != null) { writer.WriteLine(error.InnerException.Message); writer.WriteLine(error.InnerException.StackTrace); } } else { writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString()); } writer.Flush(); } }; mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi [V:{typeof(HttpApiServer).Assembly.GetName().Version}]"); OnOptionLoad(new EventOptionsReloadArgs { HttpApiServer = this, HttpOptions = this.Options }); OnStrated(new EventHttpServerStartedArgs { HttpApiServer = this }); }
public void Open() { var date = GMTDate.Default.DATE; var ct = ContentTypes.TEXT_UTF8; var a = HeaderTypeFactory.Find("Content-Length"); AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler; HttpPacket hp = new HttpPacket(this, this.FrameSerializer); var gtmdate = GMTDate.Default; string serverInfo = $"Server: beetlex.io\r\n"; HeaderTypeFactory.SERVAR_HEADER_BYTES = Encoding.ASCII.GetBytes(serverInfo); mServer = SocketFactory.CreateTcpServer(this, hp) .Setting(o => { o.SyncAccept = Options.SyncAccept; // o.IOQueues = Options.IOQueues; o.DefaultListen.Host = Options.Host; // o.IOQueueEnabled = Options.IOQueueEnabled; o.DefaultListen.Port = Options.Port; o.BufferSize = Options.BufferSize; o.LogLevel = Options.LogLevel; o.Combined = Options.PacketCombined; o.SessionTimeOut = Options.SessionTimeOut; o.UseIPv6 = Options.UseIPv6; o.BufferPoolMaxMemory = Options.BufferPoolMaxMemory; o.LittleEndian = false; o.Statistical = Options.Statistical; o.BufferPoolGroups = Options.BufferPoolGroups; o.BufferPoolSize = Options.BufferPoolSize; o.PrivateBufferPoolSize = Options.MaxBodyLength; o.MaxWaitMessages = Options.MaxWaitQueue; }); if (Options.IOQueueEnabled) { mRequestIOQueues = new DispatchCenter <IOQueueProcessArgs>(OnIOQueueProcess, Options.IOQueues); } if (Options.SSL) { mServer.Setting(o => { o.AddListenSSL(Options.CertificateFile, Options.CertificatePassword, o.DefaultListen.Host, Options.SSLPort); }); } Name = "BeetleX Http Server"; if (mAssemblies != null) { foreach (System.Reflection.Assembly assembly in mAssemblies) { mResourceCenter.LoadManifestResource(assembly); } } mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly); mResourceCenter.Path = Options.StaticResourcePath; mResourceCenter.Debug = Options.Debug; mResourceCenter.Load(); ModuleManager.Load(); if (Options.ManageApiEnabled) { ServerController serverStatusController = new ServerController(); mActionFactory.Register(serverStatusController); } StartTime = DateTime.Now; mServer.WriteLogo = WriteLogo ?? OutputLogo; InitFromCommandLineArgs(mServer); mServer.Open(); mServerCounter = new ServerCounter(this); // mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase; mUrlRewrite.Load(); //mUrlRewrite.AddRegion(this.Options.Routes); HeaderTypeFactory.Find(HeaderTypeFactory.HOST); AppDomain.CurrentDomain.UnhandledException += (s, e) => { using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt")) { Exception error = e.ExceptionObject as Exception; writer.WriteLine(DateTime.Now); if (error != null) { writer.WriteLine(error.Message); writer.WriteLine(error.StackTrace); if (error.InnerException != null) { writer.WriteLine(error.InnerException.Message); writer.WriteLine(error.InnerException.StackTrace); } } else { writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString()); } writer.Flush(); } }; mIPLimit = new IPLimit(this); OnOptionLoad(new EventOptionsReloadArgs { HttpApiServer = this, HttpOptions = this.Options }); OnStrated(new EventHttpServerStartedArgs { HttpApiServer = this }); if (Options.Virtuals != null) { foreach (var item in Options.Virtuals) { item.Verify(); if (EnableLog(LogType.Info)) { Log(LogType.Info, $"Set virtual folder {item.Folder} to {item.Path}"); } } } }