diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-16 23:04:10 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-16 23:04:10 -0400 |
| commit | 6130cb2403662596bba0474494372446d9caa3c3 (patch) | |
| tree | 8068a437340aa7e904965caf7e50053c433623d0 /MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs | |
| parent | 5363cb2719752732db17199ce9ed27743f0a80a1 (diff) | |
adjust discovery of local ip addresses
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 15d1eea6d..d88a04063 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -14,7 +14,6 @@ using ServiceStack.Host.HttpListener; using ServiceStack.Logging; using ServiceStack.Web; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -40,15 +39,26 @@ namespace MediaBrowser.Server.Implementations.HttpServer public event EventHandler<WebSocketConnectEventArgs> WebSocketConnected; - private readonly ConcurrentDictionary<string, string> _localEndPoints = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase); - + private readonly List<string> _localEndpoints = new List<string>(); + + private readonly ReaderWriterLockSlim _localEndpointLock = new ReaderWriterLockSlim(); + /// <summary> /// Gets the local end points. /// </summary> /// <value>The local end points.</value> public IEnumerable<string> LocalEndPoints { - get { return _listener == null ? new List<string>() : _localEndPoints.Keys.ToList(); } + get + { + _localEndpointLock.EnterReadLock(); + + var list = _localEndpoints.ToList(); + + _localEndpointLock.ExitReadLock(); + + return list; + } } public HttpListenerHost(IApplicationHost applicationHost, ILogManager logManager, string serviceName, string handlerPath, string defaultRedirectPath, params Assembly[] assembliesWithServices) @@ -156,7 +166,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer private void OnRequestReceived(string localEndPoint) { - _localEndPoints.GetOrAdd(localEndPoint, localEndPoint); + if (_localEndpointLock.TryEnterWriteLock(100)) + { + var list = _localEndpoints.ToList(); + + list.Remove(localEndPoint); + list.Insert(0, localEndPoint); + + _localEndpointLock.ExitWriteLock(); + } } /// <summary> |
