Exemplo n.º 1
0
 private void Init()
 {
     mReceiveDispatchCenter = new DispatchCenter <RPCPacket>(OnProcess);
     mAwaiterFactory        = new Awaiter.AwaiterFactory(Awaiter.AwaiterFactory.CLIENT_START, Awaiter.AwaiterFactory.CLIENT_END);
     InitConnect();
     mPingTimer = new System.Threading.Timer(OnPing, null, 10000, 10000);
 }
Exemplo n.º 2
0
 public AwaiterFactory(int startid, int end)
 {
     mID           = startid;
     mStartID      = startid;
     mEndID        = end;
     mTimer        = new System.Threading.Timer(OnTimeout, null, 1000, 1000);
     mTimeDispatch = new DispatchCenter <AwaiterItem>(OnTimeProcess);
 }
Exemplo n.º 3
0
 public XRPCClient(string host, int port, int maxConnections = 2)
 {
     Host = host;
     Port = port;
     mReceiveDispatchCenter = new DispatchCenter <Response>(OnProcess);
     MaxConnections         = maxConnections;
     mAwaiterFactory        = new Awaiter.AwaiterFactory();
 }
Exemplo n.º 4
0
 private void Start()
 {
     dispatchCenter = GameObject.Find("Game Manager").GetComponent <DispatchCenter>();
 }
Exemplo n.º 5
0
        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);
            var        gtmdate    = GMTDate.Default;
            string     serverInfo = $"Server: BeetleX[{typeof(BeetleX.BXException).Assembly.GetName().Version}]/FastHttpApi[{typeof(HttpApiServer).Assembly.GetName().Version}]\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.PrivateBufferPool     = Options.PrivateBufferPool;
                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.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();
                }
            };

            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi [IOQueue:{Options.IOQueueEnabled}|Threads:{Options.IOQueues}] [V:{typeof(HttpApiServer).Assembly.GetName().Version}]");
            OnOptionLoad(new EventOptionsReloadArgs {
                HttpApiServer = this, HttpOptions = this.Options
            });
            OnStrated(new EventHttpServerStartedArgs {
                HttpApiServer = this
            });
        }
Exemplo n.º 6
0
 static ResultDispatch()
 {
     DispatchCenter = new DispatchCenter <RedisRequest>(OnExecute);
 }
Exemplo n.º 7
0
 public static void SetThreads(int threads)
 {
     DispatchCenter = new DispatchCenter <RedisRequest>(OnExecute, threads);
 }