wasSharpNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 10  →  ?path2? @ 9
/Network/HTTP/HTTPServer.cs
@@ -14,54 +14,43 @@
public abstract class HTTPServer
{
private int activeRequests;
private readonly HttpListener HTTPListener = new HttpListener()
{
AuthenticationSchemes = AuthenticationSchemes.None
};
private readonly HttpListener HTTPListener = new HttpListener();
private int processedRequests;
 
private readonly AutoResetEvent StopServerEvent = new AutoResetEvent(false);
private readonly AutoResetEvent ServerStoppedEvent = new AutoResetEvent(false);
private readonly ManualResetEvent stopEvent = new ManualResetEvent(false);
 
public AuthenticationSchemes AuthenticationSchemes
public HashSet<string> Prefixes { get; set; } = new HashSet<string>();
 
public AuthenticationSchemes AuthenticationSchemes { get; set; } = AuthenticationSchemes.None;
 
public bool IsRunning => HTTPListener.IsListening;
 
public bool Start()
{
get
foreach (var prefix in Prefixes)
{
return HTTPListener.AuthenticationSchemes;
if (!HTTPListener.Prefixes.Contains(prefix))
HTTPListener.Prefixes.Add(prefix);
}
set
{
HTTPListener.AuthenticationSchemes = value;
}
}
 
public bool IsRunning => HTTPListener.IsListening;
// Set up HTTP listener.
HTTPListener.AuthenticationSchemes = AuthenticationSchemes;
 
public bool Start(IEnumerable<string> prefixes)
{
// Do not start the HTTP server if it is already running.
if (HTTPListener.IsListening)
return false;
 
// Add all prefixes.
foreach (var prefix in prefixes)
{
HTTPListener.Prefixes.Add(prefix);
}
 
// Do not bomb if the client disconnects.
HTTPListener.IgnoreWriteExceptions = true;
HTTPListener.Start();
ThreadPool.QueueUserWorkItem(Listen, new HTTPServerCallbackState(HTTPListener));
var state = new HTTPServerCallbackState(HTTPListener);
ThreadPool.QueueUserWorkItem(Listen, state);
return true;
}
 
public bool Stop()
{
StopServerEvent.Set();
ServerStoppedEvent.WaitOne();
HTTPListener.Prefixes.Clear();
return true;
return stopEvent.Set();
}
 
private void Listen(object state)
@@ -71,7 +60,7 @@
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, stopEvent});
 
if (n.Equals(1))
{
@@ -79,8 +68,6 @@
break;
}
}
 
ServerStoppedEvent.Set();
}
 
public abstract void ProcessHTTPContext(HttpListenerContext context);