コード例 #1
0
ファイル: EpollHandler.cs プロジェクト: obender12/hl18
        // constructor
        public EpollHandler(EpollServer server)
            : base() // base class is a reusable HttpCtx
        {
            this.server  = server;
            bufferHandle = GCHandle.Alloc(Buffer, GCHandleType.Pinned);
            bufferPtr    = bufferHandle.AddrOfPinnedObject();

            state        = EState.Idle;
            totalRead    = 0;
            totalWritten = 0;
        }
コード例 #2
0
        // constructor
        public EpollListener(EpollServer server)
        {
            this.server = server; // for creating handlers

            // create the epoll fd
            epfd = Syscall.epoll_create(1);
            if (epfd < 0)
            {
                throw new Exception($"Call to {nameof(Syscall.epoll_create)} failed with code: {Stdlib.GetLastError()}");
            }

            // create and attach the listener socket
            listenerSocket = Syscall.socket(UnixAddressFamily.AF_INET, UnixSocketType.SOCK_STREAM, UnixSocketProtocol.IPPROTO_TCP);
            Log.Epoll("Listener socket is {0}", listenerSocket);
            OnAttach(listenerSocket);

            // bind to port 80
            var endpoint = new IPEndPoint(IPAddress.Any, 80);

            bind(endpoint, 1024);
            Log.Info("Listening on port " + endpoint.Port);
        }
コード例 #3
0
ファイル: Router.cs プロジェクト: obender12/hl18
        public void Tick()
        {
            int useTimeout = 0; // using timeout is dangerous with cached requests

            switch (Phase)
            {
            case EPhase.P01:
                if (getCounter > 0)
                {
                    Phase = EPhase.P1;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 1 has started");
                    lastCall = Stats.Watch.Elapsed;
                }
                break;

            case EPhase.P1:
                if (getCounter >= phase1Gets || useTimeout > 0 && (Stats.Watch.Elapsed - lastCall) > TimeSpan.FromMilliseconds(useTimeout))
                {
                    Phase = EPhase.P12;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 1 has ended");
                    GetGroup.CachedResults.Clear();
                    GetFilter.CachedResults.Clear();
                    Garbage.CollectAll();
                }
                if (postCounter > 0 /*how did we miss it?*/)
                {
                    GetGroup.CachedResults.Clear();
                    GetFilter.CachedResults.Clear();
                    Phase = EPhase.P2;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 2 has started unexpectedly");
                }
                break;

            case EPhase.P12:
                if (postCounter > 0)
                {
                    Phase = EPhase.P2;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 2 has started");
                    lastCall = Stats.Watch.Elapsed;
                }
                break;

            case EPhase.P2:
                if (postCounter >= phase2Posts || useTimeout > 0 && (Stats.Watch.Elapsed - lastCall) > TimeSpan.FromMilliseconds(useTimeout))
                {
                    Phase = EPhase.P23;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 2 has ended");
                    GetGroup.CachedResults.Clear();
                    GetFilter.CachedResults.Clear();
                    Garbage.CollectAll();
                    store.Prepare(false);
                    Garbage.CollectAll();
                }
                break;

            case EPhase.P23:
                if (getCounter > phase1Gets)
                {
                    Phase = EPhase.P3;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 3 has started");
                    lastCall = Stats.Watch.Elapsed;
                }
                break;

            case EPhase.P3:
                if (getCounter >= phase1Gets + phase3Gets || useTimeout > 0 && (Stats.Watch.Elapsed - lastCall) > TimeSpan.FromMilliseconds(useTimeout))
                {
                    Phase = EPhase.PEND;
                    OnPhaseChanged(Phase);
                    Log.Info("Phase 3 has ended");
                    Stats.DisplayContextTime();
                    Mapper.DisplayStats();
                    EpollServer.DisplayServerStats();
                }
                break;
            }

            // 5 sec report
            var now = Stats.Watch.Elapsed;

            if ((now - lastReport).TotalMilliseconds > 4000)
            {
                lastReport = now;
                if (Phase != EPhase.P01)
                {
                    Console.WriteLine("{0} M{1} S{2}/{3}", lastReport.ToString(@"mm\:ss"),
                                      GC.GetTotalMemory(false) / 1024 / 1024, EpollHandler.OpenedSockets, EpollHandler.ClosedSockets);
                }
            }
        }