From d8df50efef9617270a652817b98c17f38d3c1273 Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 16 Feb 2015 16:41:58 +0900 Subject: [PATCH] Added getEndPointListener (string, int, HttpListener, bool) method to the EndPointManager class --- websocket-sharp/Net/EndPointManager.cs | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/websocket-sharp/Net/EndPointManager.cs b/websocket-sharp/Net/EndPointManager.cs index 30199f98..0267fb51 100644 --- a/websocket-sharp/Net/EndPointManager.cs +++ b/websocket-sharp/Net/EndPointManager.cs @@ -123,6 +123,53 @@ namespace WebSocketSharp.Net return epl; } + private static EndPointListener getEndPointListener ( + string host, int port, HttpListener httpListener, bool secure) + { + IPAddress addr; + if (host == "*") { + addr = IPAddress.Any; + } + else if (!IPAddress.TryParse (host, out addr)) { + try { + var iphost = Dns.GetHostEntry (host); + addr = iphost != null + ? iphost.AddressList[0] + : IPAddress.Any; + } + catch { + addr = IPAddress.Any; + } + } + + Dictionary eps = null; + if (_ipToEndpoints.ContainsKey (addr)) { + eps = _ipToEndpoints[addr]; + } + else { + eps = new Dictionary (); + _ipToEndpoints[addr] = eps; + } + + EndPointListener epl = null; + if (eps.ContainsKey (port)) { + epl = eps[port]; + } + else { + epl = new EndPointListener ( + addr, + port, + secure, + httpListener.CertificateFolderPath, + httpListener.SslConfiguration, + httpListener.ReuseAddress); + + eps[port] = epl; + } + + return epl; + } + private static void removePrefix (string uriPrefix, HttpListener httpListener) { var pref = new HttpListenerPrefix (uriPrefix);