Renamed the ListenerPrefix class to the HttpListenerPrefix class
This commit is contained in:
parent
93993790f1
commit
d156dffd55
@ -53,16 +53,16 @@ namespace WebSocketSharp.Net
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private List<ListenerPrefix> _all; // host == '+'
|
||||
private X509Certificate2 _cert;
|
||||
private static readonly string _defaultCertFolderPath;
|
||||
private IPEndPoint _endpoint;
|
||||
private Dictionary<ListenerPrefix, HttpListener> _prefixes;
|
||||
private bool _secure;
|
||||
private Socket _socket;
|
||||
private List<ListenerPrefix> _unhandled; // host == '*'
|
||||
private Dictionary<HttpConnection, HttpConnection> _unregistered;
|
||||
private object _unregisteredSync;
|
||||
private List<HttpListenerPrefix> _all; // host == '+'
|
||||
private X509Certificate2 _cert;
|
||||
private static readonly string _defaultCertFolderPath;
|
||||
private IPEndPoint _endpoint;
|
||||
private Dictionary<HttpListenerPrefix, HttpListener> _prefixes;
|
||||
private bool _secure;
|
||||
private Socket _socket;
|
||||
private List<HttpListenerPrefix> _unhandled; // host == '*'
|
||||
private Dictionary<HttpConnection, HttpConnection> _unregistered;
|
||||
private object _unregisteredSync;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -93,7 +93,7 @@ namespace WebSocketSharp.Net
|
||||
throw new ArgumentException ("No server certificate could be found.");
|
||||
}
|
||||
|
||||
_prefixes = new Dictionary<ListenerPrefix, HttpListener> ();
|
||||
_prefixes = new Dictionary<HttpListenerPrefix, HttpListener> ();
|
||||
|
||||
_unregistered = new Dictionary<HttpConnection, HttpConnection> ();
|
||||
_unregisteredSync = ((ICollection) _unregistered).SyncRoot;
|
||||
@ -132,7 +132,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void addSpecial (List<ListenerPrefix> prefixes, ListenerPrefix prefix)
|
||||
private static void addSpecial (List<HttpListenerPrefix> prefixes, HttpListenerPrefix prefix)
|
||||
{
|
||||
if (prefixes == null)
|
||||
return;
|
||||
@ -196,7 +196,7 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
private static HttpListener matchFromList (
|
||||
string host, string path, List<ListenerPrefix> list, out ListenerPrefix prefix)
|
||||
string host, string path, List<HttpListenerPrefix> list, out HttpListenerPrefix prefix)
|
||||
{
|
||||
prefix = null;
|
||||
if (list == null)
|
||||
@ -260,7 +260,7 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
}
|
||||
|
||||
private static bool removeSpecial (List<ListenerPrefix> prefixes, ListenerPrefix prefix)
|
||||
private static bool removeSpecial (List<HttpListenerPrefix> prefixes, HttpListenerPrefix prefix)
|
||||
{
|
||||
if (prefixes == null)
|
||||
return false;
|
||||
@ -277,7 +277,7 @@ namespace WebSocketSharp.Net
|
||||
return false;
|
||||
}
|
||||
|
||||
private HttpListener searchListener (Uri uri, out ListenerPrefix prefix)
|
||||
private HttpListener searchListener (Uri uri, out HttpListenerPrefix prefix)
|
||||
{
|
||||
prefix = null;
|
||||
if (uri == null)
|
||||
@ -354,15 +354,15 @@ namespace WebSocketSharp.Net
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddPrefix (ListenerPrefix prefix, HttpListener httpListener)
|
||||
public void AddPrefix (HttpListenerPrefix prefix, HttpListener httpListener)
|
||||
{
|
||||
List<ListenerPrefix> current, future;
|
||||
List<HttpListenerPrefix> current, future;
|
||||
if (prefix.Host == "*") {
|
||||
do {
|
||||
current = _unhandled;
|
||||
future = current != null
|
||||
? new List<ListenerPrefix> (current)
|
||||
: new List<ListenerPrefix> ();
|
||||
? new List<HttpListenerPrefix> (current)
|
||||
: new List<HttpListenerPrefix> ();
|
||||
|
||||
prefix.Listener = httpListener;
|
||||
addSpecial (future, prefix);
|
||||
@ -376,8 +376,8 @@ namespace WebSocketSharp.Net
|
||||
do {
|
||||
current = _all;
|
||||
future = current != null
|
||||
? new List<ListenerPrefix> (current)
|
||||
: new List<ListenerPrefix> ();
|
||||
? new List<HttpListenerPrefix> (current)
|
||||
: new List<HttpListenerPrefix> ();
|
||||
|
||||
prefix.Listener = httpListener;
|
||||
addSpecial (future, prefix);
|
||||
@ -387,7 +387,7 @@ namespace WebSocketSharp.Net
|
||||
return;
|
||||
}
|
||||
|
||||
Dictionary<ListenerPrefix, HttpListener> prefs, prefs2;
|
||||
Dictionary<HttpListenerPrefix, HttpListener> prefs, prefs2;
|
||||
do {
|
||||
prefs = _prefixes;
|
||||
if (prefs.ContainsKey (prefix)) {
|
||||
@ -399,7 +399,7 @@ namespace WebSocketSharp.Net
|
||||
return;
|
||||
}
|
||||
|
||||
prefs2 = new Dictionary<ListenerPrefix, HttpListener> (prefs);
|
||||
prefs2 = new Dictionary<HttpListenerPrefix, HttpListener> (prefs);
|
||||
prefs2[prefix] = httpListener;
|
||||
}
|
||||
while (Interlocked.CompareExchange (ref _prefixes, prefs2, prefs) != prefs);
|
||||
@ -407,7 +407,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
public bool BindContext (HttpListenerContext context)
|
||||
{
|
||||
ListenerPrefix pref;
|
||||
HttpListenerPrefix pref;
|
||||
var httpl = searchListener (context.Request.Url, out pref);
|
||||
if (httpl == null)
|
||||
return false;
|
||||
@ -432,15 +432,15 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePrefix (ListenerPrefix prefix, HttpListener httpListener)
|
||||
public void RemovePrefix (HttpListenerPrefix prefix, HttpListener httpListener)
|
||||
{
|
||||
List<ListenerPrefix> current, future;
|
||||
List<HttpListenerPrefix> current, future;
|
||||
if (prefix.Host == "*") {
|
||||
do {
|
||||
current = _unhandled;
|
||||
future = current != null
|
||||
? new List<ListenerPrefix> (current)
|
||||
: new List<ListenerPrefix> ();
|
||||
? new List<HttpListenerPrefix> (current)
|
||||
: new List<HttpListenerPrefix> ();
|
||||
|
||||
if (!removeSpecial (future, prefix))
|
||||
break; // Prefix not found.
|
||||
@ -455,8 +455,8 @@ namespace WebSocketSharp.Net
|
||||
do {
|
||||
current = _all;
|
||||
future = current != null
|
||||
? new List<ListenerPrefix> (current)
|
||||
: new List<ListenerPrefix> ();
|
||||
? new List<HttpListenerPrefix> (current)
|
||||
: new List<HttpListenerPrefix> ();
|
||||
|
||||
if (!removeSpecial (future, prefix))
|
||||
break; // Prefix not found.
|
||||
@ -467,13 +467,13 @@ namespace WebSocketSharp.Net
|
||||
return;
|
||||
}
|
||||
|
||||
Dictionary<ListenerPrefix, HttpListener> prefs, prefs2;
|
||||
Dictionary<HttpListenerPrefix, HttpListener> prefs, prefs2;
|
||||
do {
|
||||
prefs = _prefixes;
|
||||
if (!prefs.ContainsKey (prefix))
|
||||
break;
|
||||
|
||||
prefs2 = new Dictionary<ListenerPrefix, HttpListener> (prefs);
|
||||
prefs2 = new Dictionary<HttpListenerPrefix, HttpListener> (prefs);
|
||||
prefs2.Remove (prefix);
|
||||
}
|
||||
while (Interlocked.CompareExchange (ref _prefixes, prefs2, prefs) != prefs);
|
||||
|
@ -73,7 +73,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
private static void addPrefix (string uriPrefix, HttpListener httpListener)
|
||||
{
|
||||
var pref = new ListenerPrefix (uriPrefix);
|
||||
var pref = new HttpListenerPrefix (uriPrefix);
|
||||
if (pref.Path.IndexOf ('%') != -1)
|
||||
throw new HttpListenerException (400, "Invalid path."); // TODO: Code?
|
||||
|
||||
@ -118,7 +118,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
private static void removePrefix (string uriPrefix, HttpListener httpListener)
|
||||
{
|
||||
var pref = new ListenerPrefix (uriPrefix);
|
||||
var pref = new HttpListenerPrefix (uriPrefix);
|
||||
if (pref.Path.IndexOf ('%') != -1)
|
||||
return;
|
||||
|
||||
|
@ -64,7 +64,7 @@ namespace WebSocketSharp.Net
|
||||
private EndPointListener _listener;
|
||||
private ResponseStream _outputStream;
|
||||
private int _position;
|
||||
private ListenerPrefix _prefix;
|
||||
private HttpListenerPrefix _prefix;
|
||||
private MemoryStream _requestBuffer;
|
||||
private int _reuses;
|
||||
private bool _secure;
|
||||
@ -123,7 +123,7 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
}
|
||||
|
||||
public ListenerPrefix Prefix {
|
||||
public HttpListenerPrefix Prefix {
|
||||
get {
|
||||
return _prefix;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#region License
|
||||
/*
|
||||
* ListenerPrefix.cs
|
||||
* HttpListenerPrefix.cs
|
||||
*
|
||||
* This code is derived from System.Net.ListenerPrefix.cs of Mono
|
||||
* (http://www.mono-project.com).
|
||||
@ -43,7 +43,7 @@ using System.Net;
|
||||
|
||||
namespace WebSocketSharp.Net
|
||||
{
|
||||
internal sealed class ListenerPrefix
|
||||
internal sealed class HttpListenerPrefix
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
@ -59,8 +59,8 @@ namespace WebSocketSharp.Net
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
// Must be called after calling ListenerPrefix.CheckUriPrefix.
|
||||
public ListenerPrefix (string uriPrefix)
|
||||
// Must be called after calling HttpListenerPrefix.CheckPrefix.
|
||||
public HttpListenerPrefix (string uriPrefix)
|
||||
{
|
||||
_original = uriPrefix;
|
||||
parse (uriPrefix);
|
||||
@ -140,6 +140,7 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
_path = uriPrefix.Substring (root);
|
||||
|
||||
var pathLen = _path.Length;
|
||||
if (pathLen > 1)
|
||||
_path = _path.Substring (0, pathLen - 1);
|
||||
@ -149,7 +150,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
#region public Methods
|
||||
|
||||
public static void CheckUriPrefix (string uriPrefix)
|
||||
public static void CheckPrefix (string uriPrefix)
|
||||
{
|
||||
if (uriPrefix == null)
|
||||
throw new ArgumentNullException ("uriPrefix");
|
||||
@ -189,10 +190,10 @@ namespace WebSocketSharp.Net
|
||||
throw new ArgumentException ("Ends without '/'.");
|
||||
}
|
||||
|
||||
// Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection.
|
||||
// Equals and GetHashCode are required to detect duplicates in any collection.
|
||||
public override bool Equals (Object obj)
|
||||
{
|
||||
var pref = obj as ListenerPrefix;
|
||||
var pref = obj as HttpListenerPrefix;
|
||||
return pref != null && pref._original == _original;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace WebSocketSharp.Net
|
||||
public void Add (string uriPrefix)
|
||||
{
|
||||
_listener.CheckDisposed ();
|
||||
ListenerPrefix.CheckUriPrefix (uriPrefix);
|
||||
HttpListenerPrefix.CheckPrefix (uriPrefix);
|
||||
|
||||
if (_prefixes.Contains (uriPrefix))
|
||||
return;
|
||||
|
@ -86,7 +86,6 @@
|
||||
<Compile Include="Net\HttpStreamAsyncResult.cs" />
|
||||
<Compile Include="Net\HttpUtility.cs" />
|
||||
<Compile Include="Net\ListenerAsyncResult.cs" />
|
||||
<Compile Include="Net\ListenerPrefix.cs" />
|
||||
<Compile Include="Net\RequestStream.cs" />
|
||||
<Compile Include="Net\ResponseStream.cs" />
|
||||
<Compile Include="Net\WebHeaderCollection.cs" />
|
||||
@ -134,6 +133,7 @@
|
||||
<Compile Include="HttpRequest.cs" />
|
||||
<Compile Include="HttpResponse.cs" />
|
||||
<Compile Include="Server\WebSocketBehavior.cs" />
|
||||
<Compile Include="Net\HttpListenerPrefix.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user