diff --git a/websocket-sharp/Net/EndPointListener.cs b/websocket-sharp/Net/EndPointListener.cs index 67fa2639..23d3d802 100644 --- a/websocket-sharp/Net/EndPointListener.cs +++ b/websocket-sharp/Net/EndPointListener.cs @@ -390,6 +390,65 @@ namespace WebSocketSharp.Net #region Public Methods + public void AddPrefix (HttpListenerPrefix prefix) + { + List current, future; + + if (prefix.Host == "*") { + do { + current = _unhandled; + future = current != null + ? new List (current) + : new List (); + + addSpecial (future, prefix); + } + while ( + Interlocked.CompareExchange (ref _unhandled, future, current) != current + ); + + return; + } + + if (prefix.Host == "+") { + do { + current = _all; + future = current != null + ? new List (current) + : new List (); + + addSpecial (future, prefix); + } + while ( + Interlocked.CompareExchange (ref _all, future, current) != current + ); + + return; + } + + Dictionary prefs, prefs2; + + do { + prefs = _prefixes; + + if (prefs.ContainsKey (prefix)) { + if (prefs[prefix] != prefix.Listener) { + throw new HttpListenerException ( + 87, String.Format ("There's another listener for {0}.", prefix) + ); + } + + return; + } + + prefs2 = new Dictionary (prefs); + prefs2[prefix] = prefix.Listener; + } + while ( + Interlocked.CompareExchange (ref _prefixes, prefs2, prefs) != prefs + ); + } + public void AddPrefix (HttpListenerPrefix prefix, HttpListener listener) { List current, future;