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