Exemplo n.º 1
0
        private ConcurrentQueue <Action> postQueue = new ConcurrentQueue <Action>(); // order is important, speed is not

        // constructor
        public EpollServer(Router router)
        {
            this.router = router;
#if !EPOLL_DEBUG
            // pre-create 2000 handlers
            for (int i = 0; i < 2048; i++)
            {
                handlers[i] = new EpollHandler(this);
            }
#endif
            router.OnPhaseChanged += (phase) =>
            {
                if (phase == EPhase.P1 || phase == EPhase.P2 || phase == EPhase.P3)
                {
                    timeoutMode = 0;
                }
                else
                {
                    timeoutMode = -1;
                }
            };

            // listener single instance
            listener = new EpollListener(this);
        }
Exemplo n.º 2
0
 public EpollHandler GetHandler(int socket)
 {
     if (handlers[socket] == null)
     {
         handlers[socket] = new EpollHandler(this);
     }
     return(handlers[socket]);
 }
Exemplo n.º 3
0
        // process fully received request
        public void ProcessContext(EpollHandler ctx)
        {
#if true
            router.ProcessRequest(ctx);
            if (ctx.PostAction != null)
            {
                postQueue.Enqueue(ctx.PostAction);
            }
            ctx.PostAction = null;
            ctx.OnDoneProcessing();
#else
            Array.Copy(dummy, 0, ctx.Buffer, ctx.ResponseStart, dummy.Length);
            ctx.ResponseBodyStart  = ctx.ResponseStart + dummy.Length;
            ctx.ResponseBodyLength = dummy.Length;
            ctx.OnDoneProcessing();
#endif
        }
Exemplo n.º 4
0
        private void disconnect(EpollHandler handler)
        {
            var os = new Overspan(50);

            // detach the handler
            var socketHandle = handler.OnDetach();

            // unsubscribe from Epoll events
            Remove(socketHandle, 0);

            // close the socket
            if (Syscall.close(socketHandle) < 0)
            {
                Log.Error($"Call to close(socked) failed: {Stdlib.GetLastError()}");
            }
            Log.Epoll("[{0}] socked disconnected, closed", socketHandle);

            os.Check("disconnect()");
        }