wasSharpNET – Diff between revs 15 and 16
?pathlinks?
Rev 15 | Rev 16 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | AuthenticationSchemes = AuthenticationSchemes.None |
20 | AuthenticationSchemes = AuthenticationSchemes.None |
|
21 | }; |
21 | }; |
|
Line 22... | Line 22... | |||
22 | |
22 | |
|
Line 23... | Line -... | |||
23 | private int processedRequests; |
- | ||
24 | |
- | ||
25 | private AutoResetEvent StopServerEvent = new AutoResetEvent(false); |
- | ||
26 | private AutoResetEvent ServerStoppedEvent = new AutoResetEvent(false); |
23 | private int processedRequests; |
|
27 | |
24 | |
|
28 | public AuthenticationSchemes AuthenticationSchemes |
25 | public AuthenticationSchemes AuthenticationSchemes |
|
29 | { |
26 | { |
|
30 | get |
27 | get |
|
Line 44... | Line 41... | |||
44 | // Do not start the HTTP server if it is already running. |
41 | // Do not start the HTTP server if it is already running. |
|
45 | if (HTTPListener.IsListening) |
42 | if (HTTPListener.IsListening) |
|
46 | return false; |
43 | return false; |
|
Line 47... | Line 44... | |||
47 | |
44 | |
|
- | 45 | // Add all prefixes. |
||
48 | // Add all prefixes. |
46 | HTTPListener.Prefixes.Clear(); |
|
49 | foreach (var prefix in prefixes) |
47 | foreach (var prefix in prefixes) |
|
50 | { |
48 | { |
|
51 | HTTPListener.Prefixes.Add(prefix); |
49 | HTTPListener.Prefixes.Add(prefix); |
|
Line 58... | Line 56... | |||
58 | return true; |
56 | return true; |
|
59 | } |
57 | } |
|
Line 60... | Line 58... | |||
60 | |
58 | |
|
61 | public bool Stop() |
59 | public bool Stop() |
|
62 | { |
- | ||
63 | StopServerEvent.Set(); |
- | ||
64 | ServerStoppedEvent.WaitOne(); |
60 | { |
|
65 | HTTPListener.Prefixes.Clear(); |
61 | HTTPListener.Stop(); |
|
66 | return true; |
62 | return true; |
|
Line 67... | Line 63... | |||
67 | } |
63 | } |
|
68 | |
64 | |
|
69 | private void Listen(object state) |
65 | private void Listen(object state) |
|
Line 70... | Line 66... | |||
70 | { |
66 | { |
|
71 | var callbackState = (HTTPServerCallbackState)state; |
67 | var callbackState = (HTTPServerCallbackState)state; |
|
72 | |
68 | |
|
73 | while (callbackState.Listener.IsListening) |
- | ||
74 | { |
- | ||
75 | callbackState.Listener.BeginGetContext(ContextCallback, callbackState); |
- | ||
76 | var n = WaitHandle.WaitAny(new WaitHandle[] { callbackState.ContextRetrieved, StopServerEvent }); |
- | ||
77 | |
69 | while (callbackState.Listener.IsListening) |
|
78 | if (n.Equals(1)) |
- | ||
79 | { |
- | ||
80 | callbackState.Listener.Stop(); |
70 | { |
|
81 | break; |
- | ||
82 | } |
- | ||
83 | } |
71 | callbackState.Listener.BeginGetContext(ContextCallback, callbackState); |
|
Line 84... | Line 72... | |||
84 | |
72 | callbackState.ContextRetrieved.WaitOne(); |
|
Line 85... | Line 73... | |||
85 | ServerStoppedEvent.Set(); |
73 | } |
|
Line 123... | Line 111... | |||
123 | } |
111 | } |
|
Line 124... | Line 112... | |||
124 | |
112 | |
|
125 | public void Dispose() |
113 | public void Dispose() |
|
126 | { |
114 | { |
|
127 | Stop(); |
- | ||
128 | |
115 | Stop(); |
|
129 | HTTPListener = null; |
- | ||
130 | StopServerEvent?.Dispose(); |
- | ||
131 | ServerStoppedEvent?.Dispose(); |
- | ||
132 | |
- | ||
133 | StopServerEvent = null; |
- | ||
134 | ServerStoppedEvent = null; |
116 | HTTPListener = null; |
|
Line 135... | Line 117... | |||
135 | } |
117 | } |
|
136 | |
118 | |
|
137 | private class HTTPServerCallbackState |
119 | private class HTTPServerCallbackState |