aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-09-13 20:37:04 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-09-13 20:37:04 -0400
commit4f3ea6c6c3cdde7f4b8d21dc97c711635d73b4e0 (patch)
tree785572b2b4f21f6e310758c32750fd41fc31eb05 /MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs
parent8d20621e19781046d79b61340d89cbb9084f7393 (diff)
adjust socket listener
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs')
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs
index d39d82e80..c91785111 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs
@@ -15,7 +15,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
public class WebSocketSharpListener : IHttpListener
{
private HttpListener _listener;
- private readonly ManualResetEvent _listenForNextRequest = new ManualResetEvent(false);
+ private readonly ManualResetEventSlim _listenForNextRequest = new ManualResetEventSlim(false);
private readonly ILogger _logger;
private readonly Action<string> _endpointListener;
@@ -64,7 +64,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
try
{
_listener.BeginGetContext(ListenerCallback, _listener);
- _listenForNextRequest.WaitOne();
+ _listenForNextRequest.Wait();
}
catch (Exception ex)
{
@@ -78,8 +78,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
// Handle the processing of a request in here.
private void ListenerCallback(IAsyncResult asyncResult)
{
- _listenForNextRequest.Set();
-
var listener = asyncResult.AsyncState as HttpListener;
HttpListenerContext context;
@@ -90,7 +88,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{
if (!isListening)
{
- _logger.Debug("Ignoring ListenerCallback() as HttpListener is no longer listening"); return;
+ _logger.Debug("Ignoring ListenerCallback() as HttpListener is no longer listening");
+ return;
}
// The EndGetContext() method, as with all Begin/End asynchronous methods in the .NET Framework,
// blocks until there is a request to be processed or some type of data is available.
@@ -106,6 +105,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
_logger.Warn(errMsg);
return;
}
+ finally
+ {
+ _listenForNextRequest.Set();
+ }
Task.Factory.StartNew(() => InitTask(context));
}