wasSharpNET – Diff between revs 22 and 27

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 22 Rev 27
Line 11... Line 11...
11   11  
12 namespace wasSharpNET.Network.HTTP 12 namespace wasSharpNET.Network.HTTP
13 { 13 {
14 public abstract class HTTPServer : IDisposable 14 public abstract class HTTPServer : IDisposable
-   15 {
-   16 private readonly ManualResetEventSlim listenStop = new ManualResetEventSlim(false);
-   17  
15 { 18 private readonly ManualResetEventSlim stopListen = new ManualResetEventSlim(false);
Line 16... Line 19...
16 private int activeRequests; 19 private int activeRequests;
Line 17... Line 20...
17   20  
Line 22... Line 25...
22 public AuthenticationSchemes AuthenticationSchemes { get; set; } = 25 public AuthenticationSchemes AuthenticationSchemes { get; set; } =
23 AuthenticationSchemes.None; 26 AuthenticationSchemes.None;
Line 24... Line 27...
24   27  
Line 25... Line 28...
25 public bool IsRunning => HTTPListener != null && HTTPListener.IsListening; 28 public bool IsRunning => HTTPListener != null && HTTPListener.IsListening;
-   29  
26   30 public void Dispose()
-   31 {
Line 27... Line 32...
27 private readonly ManualResetEventSlim stopListen = new ManualResetEventSlim(false); 32 stopListen.Set();
28 private readonly ManualResetEventSlim listenStop = new ManualResetEventSlim(false); 33 }
29   34  
30 public bool Start(List<string> prefixes) 35 public bool Start(List<string> prefixes)
Line 35... Line 40...
35 }; 40 };
Line 36... Line 41...
36   41  
37 // Add all prefixes. 42 // Add all prefixes.
38 HTTPListener.Prefixes.Clear(); 43 HTTPListener.Prefixes.Clear();
39 foreach (var prefix in prefixes) -  
40 { 44 foreach (var prefix in prefixes)
41 HTTPListener.Prefixes.Add(prefix); -  
Line 42... Line 45...
42 } 45 HTTPListener.Prefixes.Add(prefix);
43   46  
44 // Do not bomb if the client disconnects. 47 // Do not bomb if the client disconnects.
45 HTTPListener.IgnoreWriteExceptions = true; 48 HTTPListener.IgnoreWriteExceptions = true;
Line 53... Line 56...
53 return listenStop.Wait(timeout); 56 return listenStop.Wait(timeout);
54 } 57 }
Line 55... Line 58...
55   58  
56 private void Listen(object state) 59 private void Listen(object state)
57 { 60 {
Line 58... Line 61...
58 HTTPServerCallbackState callbackState = (HTTPServerCallbackState)state; 61 var callbackState = (HTTPServerCallbackState) state;
59   62  
60 while (callbackState.Listener.IsListening) 63 while (callbackState.Listener.IsListening)
Line 61... Line 64...
61 { 64 {
62 callbackState.Listener?.BeginGetContext(ContextCallback, callbackState); 65 callbackState.Listener?.BeginGetContext(ContextCallback, callbackState);
Line 63... Line 66...
63   66  
64 if (WaitHandle.WaitAny(new[] { callbackState.ContextRetrieved, stopListen.WaitHandle }) != 1) 67 if (WaitHandle.WaitAny(new[] {callbackState.ContextRetrieved, stopListen.WaitHandle}) != 1)
65 continue; 68 continue;
Line 79... Line 82...
79   82  
Line 80... Line 83...
80 public abstract void ProcessHTTPContext(HttpListenerContext context); 83 public abstract void ProcessHTTPContext(HttpListenerContext context);
81   84  
82 private void ContextCallback(IAsyncResult ar) 85 private void ContextCallback(IAsyncResult ar)
83 { 86 {
Line 84... Line 87...
84 var callbackState = (HTTPServerCallbackState)ar.AsyncState; 87 var callbackState = (HTTPServerCallbackState) ar.AsyncState;
85 HttpListenerContext httpContext; 88 HttpListenerContext httpContext;
Line 109... Line 112...
109 { 112 {
110 Interlocked.Decrement(ref activeRequests); 113 Interlocked.Decrement(ref activeRequests);
111 } 114 }
112 } 115 }
Line 113... Line -...
113   -  
114 public void Dispose() -  
115 { -  
116 stopListen.Set(); -  
117 } -  
118   116  
119 private class HTTPServerCallbackState 117 private class HTTPServerCallbackState
120 { 118 {
121 public HTTPServerCallbackState(HttpListener listener) 119 public HTTPServerCallbackState(HttpListener listener)
122 { 120 {
Line 129... Line 127...
129 public HttpListener Listener { get; } 127 public HttpListener Listener { get; }
Line 130... Line 128...
130   128  
131 public AutoResetEvent ContextRetrieved { get; } 129 public AutoResetEvent ContextRetrieved { get; }
132 } 130 }
133 } 131 }
134 } 132 }