wasSharpNET
/Network/HTTP/HTTPServer.cs |
@@ -14,10 +14,12 @@ |
public abstract class HTTPServer |
{ |
private int activeRequests; |
|
private readonly HttpListener HTTPListener = new HttpListener() |
{ |
AuthenticationSchemes = AuthenticationSchemes.None |
}; |
|
private int processedRequests; |
|
private readonly AutoResetEvent StopServerEvent = new AutoResetEvent(false); |
@@ -66,12 +68,12 @@ |
|
private void Listen(object state) |
{ |
var callbackState = (HTTPServerCallbackState) state; |
var callbackState = (HTTPServerCallbackState)state; |
|
while (callbackState.Listener.IsListening) |
{ |
callbackState.Listener.BeginGetContext(ContextCallback, callbackState); |
var n = WaitHandle.WaitAny(new WaitHandle[] {callbackState.ContextRetrieved, StopServerEvent}); |
var n = WaitHandle.WaitAny(new WaitHandle[] { callbackState.ContextRetrieved, StopServerEvent }); |
|
if (n.Equals(1)) |
{ |
@@ -87,7 +89,7 @@ |
|
private void ContextCallback(IAsyncResult ar) |
{ |
var callbackState = (HTTPServerCallbackState) ar.AsyncState; |
var callbackState = (HTTPServerCallbackState)ar.AsyncState; |
HttpListenerContext httpContext = null; |
|
Interlocked.Increment(ref processedRequests); |
@@ -135,4 +137,4 @@ |
public AutoResetEvent ContextRetrieved { get; } |
} |
} |
} |
} |