public override void Loop() { HttpListener listener = new HttpListener(); listener.Prefixes.Add($"http://{Settings.HostName}/fl-online/"); listener.Start(); while (!ExitRequested) { IAsyncResult contextResult = listener.BeginGetContext(ar => { }, null); while (!contextResult.IsCompleted) { if (ExitRequested) { break; } Thread.Sleep(MillisTimeout); } if (ExitRequested) { break; } HttpListenerContext context = listener.EndGetContext(contextResult); IEndpoint endpoint = Endpoints.FirstOrDefault(x => x.EndpointName == context.Request.Url.Segments.Last()); if (endpoint == null) { EndpointWorkItem.Serve( Settings.XOriginAllow, context.Response, new ErrorResponseObject( 404, $"Endpoint '{context.Request.Url.Segments.Last()}' does not exist." ) ); continue; } EndpointWorkItem workItem = endpoint.GetItem(context); Processor.Enqueue((endpoint, workItem)); } listener.Stop(); }
void IEndpoint.Process(EndpointWorkItem item) { Process((T)item); }