private void GetContext(IAsyncResult ar) { IHttpContext ctx; try { ctx = new HttpListenerContextAdpater(listener.EndGetContext(ar), DefaultConfiguration); //setup waiting for the next request listener.BeginGetContext(GetContext, null); } catch (Exception) { // can't get current request / end new one, probably // listner shutdown return; } if (concurretRequestSemaphore.Wait(TimeSpan.FromSeconds(5)) == false) { HandleTooBusyError(ctx); return; } try { Interlocked.Increment(ref physicalRequestsCount); HandleActualRequest(ctx); } finally { concurretRequestSemaphore.Release(); } }
private void GetContext(IAsyncResult ar) { HttpListenerContextAdpater ctx; try { HttpListenerContext httpListenerContext = listener.EndGetContext(ar); ctx = new HttpListenerContextAdpater(httpListenerContext, SystemConfiguration, bufferPool); //setup waiting for the next request listener.BeginGetContext(GetContext, null); } catch (Exception) { // can't get current request / end new one, probably // listener shutdown return; } if (concurretRequestSemaphore.Wait(TimeSpan.FromSeconds(5)) == false) { HandleTooBusyError(ctx); return; } try { Interlocked.Increment(ref physicalRequestsCount); if (ChangesQuery.IsMatch(ctx.GetRequestUrl())) { HandleChangesRequest(ctx, () => { }); } else { HandleActualRequest(ctx); } } finally { concurretRequestSemaphore.Release(); } }