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); }
public EpollHandler GetHandler(int socket) { if (handlers[socket] == null) { handlers[socket] = new EpollHandler(this); } return(handlers[socket]); }
// 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 }
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()"); }