diff --git a/websocket-sharp/Net/ChunkStream.cs b/websocket-sharp/Net/ChunkStream.cs
index dd31605a..25cf7ad7 100644
--- a/websocket-sharp/Net/ChunkStream.cs
+++ b/websocket-sharp/Net/ChunkStream.cs
@@ -1,6 +1,6 @@
//
// ChunkStream.cs
-// Copied from System.Net.ChunkStream
+// Copied from System.Net.ChunkStream.cs
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
@@ -28,7 +28,7 @@
//
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
@@ -39,6 +39,7 @@ namespace WebSocketSharp.Net {
class ChunkStream {
enum State {
+
None,
Body,
BodyFinished,
@@ -46,8 +47,9 @@ namespace WebSocketSharp.Net {
}
class Chunk {
+
public byte [] Bytes;
- public int Offset;
+ public int Offset;
public Chunk (byte [] chunk)
{
@@ -63,19 +65,29 @@ namespace WebSocketSharp.Net {
}
}
- internal WebHeaderCollection headers;
- int chunkSize;
- int chunkRead;
- State state;
- //byte [] waitBuffer;
+ #region Private Fields
+
+ int chunkRead;
+ List chunks;
+ int chunkSize;
+ bool gotit;
StringBuilder saved;
- bool sawCR;
- bool gotit;
- int trailerState;
- ArrayList chunks;
-
+ bool sawCR;
+ State state;
+ int trailerState;
+
+ #endregion
+
+ #region Internal Fields
+
+ internal WebHeaderCollection headers;
+
+ #endregion
+
+ #region Constructors
+
public ChunkStream (byte [] buffer, int offset, int size, WebHeaderCollection headers)
- : this (headers)
+ : this (headers)
{
Write (buffer, offset, size);
}
@@ -84,63 +96,89 @@ namespace WebSocketSharp.Net {
{
this.headers = headers;
saved = new StringBuilder ();
- chunks = new ArrayList ();
+ chunks = new List ();
chunkSize = -1;
}
- public void ResetBuffer ()
- {
- chunkSize = -1;
- chunkRead = 0;
- chunks.Clear ();
- }
-
- public void WriteAndReadBack (byte [] buffer, int offset, int size, ref int read)
- {
- if (offset + read > 0)
- Write (buffer, offset, offset+read);
- read = Read (buffer, offset, size);
+ #endregion
+
+ #region Properties
+
+ public int ChunkLeft {
+ get { return chunkSize - chunkRead; }
}
- public int Read (byte [] buffer, int offset, int size)
- {
- return ReadFromChunks (buffer, offset, size);
+ public bool WantMore {
+ get { return (chunkRead != chunkSize || chunkSize != 0 || state != State.None); }
}
- int ReadFromChunks (byte [] buffer, int offset, int size)
+ #endregion
+
+ #region Private Methods
+
+ State GetChunkSize (byte [] buffer, ref int offset, int size)
{
- int count = chunks.Count;
- int nread = 0;
- for (int i = 0; i < count; i++) {
- Chunk chunk = (Chunk) chunks [i];
- if (chunk == null)
- continue;
+ char c = '\0';
+ while (offset < size) {
+ c = (char) buffer [offset++];
+ if (c == '\r') {
+ if (sawCR)
+ ThrowProtocolViolation ("2 CR found.");
- if (chunk.Offset == chunk.Bytes.Length) {
- chunks [i] = null;
+ sawCR = true;
continue;
}
- nread += chunk.Read (buffer, offset + nread, size - nread);
- if (nread == size)
+ if (sawCR && c == '\n')
break;
+
+ if (c == ' ')
+ gotit = true;
+
+ if (!gotit)
+ saved.Append (c);
+
+ if (saved.Length > 20)
+ ThrowProtocolViolation ("Chunk size too long.");
}
- return nread;
- }
-
- public void Write (byte [] buffer, int offset, int size)
- {
- InternalWrite (buffer, ref offset, size);
+ if (!sawCR || c != '\n') {
+ if (offset < size)
+ ThrowProtocolViolation ("Missing \\n.");
+
+ try {
+ if (saved.Length > 0) {
+ chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
+ }
+ } catch (Exception) {
+ ThrowProtocolViolation ("Cannot parse chunk size.");
+ }
+
+ return State.None;
+ }
+
+ chunkRead = 0;
+ try {
+ chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
+ } catch (Exception) {
+ ThrowProtocolViolation ("Cannot parse chunk size.");
+ }
+
+ if (chunkSize == 0) {
+ trailerState = 2;
+ return State.Trailer;
+ }
+
+ return State.Body;
}
-
+
void InternalWrite (byte [] buffer, ref int offset, int size)
{
if (state == State.None) {
state = GetChunkSize (buffer, ref offset, size);
if (state == State.None)
return;
-
+
saved.Length = 0;
sawCR = false;
gotit = false;
@@ -151,7 +189,7 @@ namespace WebSocketSharp.Net {
if (state == State.Body)
return;
}
-
+
if (state == State.BodyFinished && offset < size) {
state = ReadCRLF (buffer, ref offset, size);
if (state == State.BodyFinished)
@@ -174,14 +212,6 @@ namespace WebSocketSharp.Net {
InternalWrite (buffer, ref offset, size);
}
- public bool WantMore {
- get { return (chunkRead != chunkSize || chunkSize != 0 || state != State.None); }
- }
-
- public int ChunkLeft {
- get { return chunkSize - chunkRead; }
- }
-
State ReadBody (byte [] buffer, ref int offset, int size)
{
if (chunkSize == 0)
@@ -197,90 +227,47 @@ namespace WebSocketSharp.Net {
offset += diff;
chunkRead += diff;
return (chunkRead == chunkSize) ? State.BodyFinished : State.Body;
-
- }
-
- State GetChunkSize (byte [] buffer, ref int offset, int size)
- {
- char c = '\0';
- while (offset < size) {
- c = (char) buffer [offset++];
- if (c == '\r') {
- if (sawCR)
- ThrowProtocolViolation ("2 CR found");
-
- sawCR = true;
- continue;
- }
-
- if (sawCR && c == '\n')
- break;
-
- if (c == ' ')
- gotit = true;
-
- if (!gotit)
- saved.Append (c);
-
- if (saved.Length > 20)
- ThrowProtocolViolation ("chunk size too long.");
- }
-
- if (!sawCR || c != '\n') {
- if (offset < size)
- ThrowProtocolViolation ("Missing \\n");
-
- try {
- if (saved.Length > 0) {
- chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
- }
- } catch (Exception) {
- ThrowProtocolViolation ("Cannot parse chunk size.");
- }
-
- return State.None;
- }
-
- chunkRead = 0;
- try {
- chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
- } catch (Exception) {
- ThrowProtocolViolation ("Cannot parse chunk size.");
- }
-
- if (chunkSize == 0) {
- trailerState = 2;
- return State.Trailer;
- }
-
- return State.Body;
- }
-
- static string RemoveChunkExtension (string input)
- {
- int idx = input.IndexOf (';');
- if (idx == -1)
- return input;
- return input.Substring (0, idx);
}
State ReadCRLF (byte [] buffer, ref int offset, int size)
{
if (!sawCR) {
if ((char) buffer [offset++] != '\r')
- ThrowProtocolViolation ("Expecting \\r");
+ ThrowProtocolViolation ("Expecting \\r.");
sawCR = true;
if (offset == size)
return State.BodyFinished;
}
-
+
if (sawCR && (char) buffer [offset++] != '\n')
- ThrowProtocolViolation ("Expecting \\n");
+ ThrowProtocolViolation ("Expecting \\n.");
return State.None;
}
+ int ReadFromChunks (byte [] buffer, int offset, int size)
+ {
+ int count = chunks.Count;
+ int nread = 0;
+ for (int i = 0; i < count; i++) {
+ var chunk = chunks [i];
+ if (chunk == null)
+ continue;
+
+ if (chunk.Offset == chunk.Bytes.Length) {
+ chunks [i] = null;
+ continue;
+ }
+
+ nread += chunk.Read (buffer, offset + nread, size - nread);
+ if (nread == size)
+ break;
+ }
+
+ return nread;
+ }
+
State ReadTrailer (byte [] buffer, ref int offset, int size)
{
char c = '\0';
@@ -292,9 +279,10 @@ namespace WebSocketSharp.Net {
offset++;
return State.None;
}
+
offset--;
}
-
+
int st = trailerState;
string stString = "\r\n\r";
while (offset < size && st < 4) {
@@ -325,7 +313,7 @@ namespace WebSocketSharp.Net {
return State.Trailer;
}
- StringReader reader = new StringReader (saved.ToString ());
+ var reader = new StringReader (saved.ToString ());
string line;
while ((line = reader.ReadLine ()) != null && line != "")
headers.Add (line);
@@ -333,10 +321,50 @@ namespace WebSocketSharp.Net {
return State.None;
}
+ static string RemoveChunkExtension (string input)
+ {
+ int idx = input.IndexOf (';');
+ if (idx == -1)
+ return input;
+
+ return input.Substring (0, idx);
+ }
+
static void ThrowProtocolViolation (string message)
{
- WebException we = new WebException (message, null, WebExceptionStatus.ServerProtocolViolation, null);
+ var we = new WebException (message, null, WebExceptionStatus.ServerProtocolViolation, null);
throw we;
}
+
+ #endregion
+
+ #region Public Methods
+
+ public int Read (byte [] buffer, int offset, int size)
+ {
+ return ReadFromChunks (buffer, offset, size);
+ }
+
+ public void ResetBuffer ()
+ {
+ chunkSize = -1;
+ chunkRead = 0;
+ chunks.Clear ();
+ }
+
+ public void Write (byte [] buffer, int offset, int size)
+ {
+ InternalWrite (buffer, ref offset, size);
+ }
+
+ public void WriteAndReadBack (byte [] buffer, int offset, int size, ref int read)
+ {
+ if (offset + read > 0)
+ Write (buffer, offset, offset + read);
+
+ read = Read (buffer, offset, size);
+ }
+
+ #endregion
}
}
diff --git a/websocket-sharp/Net/ChunkedInputStream.cs b/websocket-sharp/Net/ChunkedInputStream.cs
index df988bc0..1797dbc4 100644
--- a/websocket-sharp/Net/ChunkedInputStream.cs
+++ b/websocket-sharp/Net/ChunkedInputStream.cs
@@ -1,6 +1,6 @@
//
// ChunkedInputStream.cs
-// Copied from System.Net.ChunkedInputStream
+// Copied from System.Net.ChunkedInputStream.cs
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
@@ -25,21 +25,15 @@
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;
using System.IO;
-using System.Net;
-using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace WebSocketSharp.Net {
- class ChunkedInputStream : RequestStream
- {
- HttpListenerContext context;
- ChunkStream decoder;
- bool disposed;
- bool no_more_data;
+ class ChunkedInputStream : RequestStream {
class ReadBufferState {
@@ -60,6 +54,17 @@ namespace WebSocketSharp.Net {
}
}
+ #region Fields
+
+ HttpListenerContext context;
+ ChunkStream decoder;
+ bool disposed;
+ bool no_more_data;
+
+ #endregion
+
+ #region Constructor
+
public ChunkedInputStream (
HttpListenerContext context, Stream stream, byte [] buffer, int offset, int length)
: base (stream, buffer, offset, length)
@@ -69,15 +74,23 @@ namespace WebSocketSharp.Net {
decoder = new ChunkStream (coll);
}
+ #endregion
+
+ #region Property
+
public ChunkStream Decoder {
get { return decoder; }
set { decoder = value; }
}
+ #endregion
+
+ #region Private Method
+
void OnRead (IAsyncResult base_ares)
{
- ReadBufferState rb = (ReadBufferState) base_ares.AsyncState;
- HttpStreamAsyncResult ares = rb.Ares;
+ var rb = (ReadBufferState) base_ares.AsyncState;
+ var ares = rb.Ares;
try {
int nread = base.EndRead (base_ares);
decoder.Write (ares.Buffer, ares.Offset, nread);
@@ -90,6 +103,7 @@ namespace WebSocketSharp.Net {
ares.Complete ();
return;
}
+
ares.Offset = 0;
ares.Count = Math.Min (8192, decoder.ChunkLeft + 6);
base.BeginRead (ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
@@ -99,6 +113,10 @@ namespace WebSocketSharp.Net {
}
}
+ #endregion
+
+ #region Public Methods
+
public override IAsyncResult BeginRead (
byte [] buffer, int offset, int count, AsyncCallback cback, object state)
{
@@ -110,18 +128,19 @@ namespace WebSocketSharp.Net {
int len = buffer.Length;
if (offset < 0 || offset > len)
- throw new ArgumentOutOfRangeException ("offset exceeds the size of buffer");
+ throw new ArgumentOutOfRangeException ("'offset' exceeds the size of buffer.");
if (count < 0 || offset > len - count)
- throw new ArgumentOutOfRangeException ("offset+size exceeds the size of buffer");
+ throw new ArgumentOutOfRangeException ("'offset' + 'count' exceeds the size of buffer.");
- HttpStreamAsyncResult ares = new HttpStreamAsyncResult ();
+ var ares = new HttpStreamAsyncResult ();
ares.Callback = cback;
ares.State = state;
if (no_more_data) {
ares.Complete ();
return ares;
}
+
int nread = decoder.Read (buffer, offset, count);
offset += nread;
count -= nread;
@@ -131,16 +150,18 @@ namespace WebSocketSharp.Net {
ares.Complete ();
return ares;
}
+
if (!decoder.WantMore) {
no_more_data = nread == 0;
ares.Count = nread;
ares.Complete ();
return ares;
}
+
ares.Buffer = new byte [8192];
ares.Offset = 0;
ares.Count = 8192;
- ReadBufferState rb = new ReadBufferState (buffer, offset, count, ares);
+ var rb = new ReadBufferState (buffer, offset, count, ares);
rb.InitialCount += nread;
base.BeginRead (ares.Buffer, ares.Offset, ares.Count, OnRead, rb);
return ares;
@@ -159,23 +180,25 @@ namespace WebSocketSharp.Net {
if (disposed)
throw new ObjectDisposedException (GetType ().ToString ());
- HttpStreamAsyncResult my_ares = ares as HttpStreamAsyncResult;
if (ares == null)
- throw new ArgumentException ("Invalid IAsyncResult", "ares");
+ throw new ArgumentException ("Invalid IAsyncResult.", "ares");
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne ();
- if (my_ares.Error != null)
+ var ares_ = ares as HttpStreamAsyncResult;
+ if (ares_.Error != null)
throw new HttpListenerException (400, "I/O operation aborted.");
- return my_ares.Count;
+ return ares_.Count;
}
public override int Read ([In,Out] byte [] buffer, int offset, int count)
{
- IAsyncResult ares = BeginRead (buffer, offset, count, null, null);
+ var ares = BeginRead (buffer, offset, count, null, null);
return EndRead (ares);
}
+
+ #endregion
}
}
diff --git a/websocket-sharp/Net/HttpListenerPrefixCollection.cs b/websocket-sharp/Net/HttpListenerPrefixCollection.cs
index 904c8f46..4c5a35a3 100644
--- a/websocket-sharp/Net/HttpListenerPrefixCollection.cs
+++ b/websocket-sharp/Net/HttpListenerPrefixCollection.cs
@@ -1,12 +1,12 @@
//
// HttpListenerPrefixCollection.cs
-// Copied from System.Net.HttpListenerPrefixCollection
+// Copied from System.Net.HttpListenerPrefixCollection.cs
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
-// Copyright (c) 2012 sta.blockhead (sta.blockhead@gmail.com)
+// Copyright (c) 2012-2013 sta.blockhead (sta.blockhead@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -31,38 +31,104 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using System.Net;
namespace WebSocketSharp.Net {
+ ///
+ /// Provides the collection used to store the URI prefixes for the .
+ ///
public class HttpListenerPrefixCollection : ICollection, IEnumerable, IEnumerable
{
+ #region Fields
+
HttpListener listener;
List prefixes;
+ #endregion
+
+ #region Private Constructor
+
private HttpListenerPrefixCollection ()
{
prefixes = new List ();
}
+ #endregion
+
+ #region Internal Constructor
+
internal HttpListenerPrefixCollection (HttpListener listener)
: this ()
{
this.listener = listener;
}
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets the number of prefixes contained in the .
+ ///
+ ///
+ /// A that contains the number of prefixes.
+ ///
public int Count {
get { return prefixes.Count; }
}
+ ///
+ /// Gets a value indicating whether access to the is read-only.
+ ///
+ ///
+ /// Always returns false.
+ ///
public bool IsReadOnly {
get { return false; }
}
+ ///
+ /// Gets a value indicating whether access to the is synchronized.
+ ///
+ ///
+ /// Always returns false.
+ ///
public bool IsSynchronized {
get { return false; }
}
+ #endregion
+
+ #region Explicit Interface Implementation
+
+ ///
+ /// Gets an object that can be used to iterate through the .
+ ///
+ ///
+ /// An object that implements the interface and provides access to
+ /// the URI prefix strings in the .
+ ///
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return prefixes.GetEnumerator ();
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ ///
+ /// Adds the specified to the .
+ ///
+ ///
+ /// A that contains a URI prefix to add.
+ ///
+ ///
+ /// is .
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
public void Add (string uriPrefix)
{
listener.CheckDisposed ();
@@ -75,6 +141,12 @@ namespace WebSocketSharp.Net {
EndPointManager.AddPrefix (uriPrefix, listener);
}
+ ///
+ /// Removes all URI prefixes from the .
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
public void Clear ()
{
listener.CheckDisposed ();
@@ -83,34 +155,96 @@ namespace WebSocketSharp.Net {
EndPointManager.RemoveListener (listener);
}
+ ///
+ /// Returns a value indicating whether the contains
+ /// the specified .
+ ///
+ ///
+ /// true if the contains the specified ;
+ /// otherwise, false.
+ ///
+ ///
+ /// A that contains a URI prefix to test.
+ ///
+ ///
+ /// is .
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
public bool Contains (string uriPrefix)
{
listener.CheckDisposed ();
- return prefixes.Contains (uriPrefix);
- }
+ if (uriPrefix == null)
+ throw new ArgumentNullException ("uriPrefix");
- public void CopyTo (string [] array, int offset)
- {
- listener.CheckDisposed ();
- prefixes.CopyTo (array, offset);
+ return prefixes.Contains (uriPrefix);
}
+ ///
+ /// Copies the contents of the to the specified .
+ ///
+ ///
+ /// An that receives the URI prefix strings in the .
+ ///
+ ///
+ /// An that contains the zero-based index in at which copying begins.
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
public void CopyTo (Array array, int offset)
{
listener.CheckDisposed ();
((ICollection) prefixes).CopyTo (array, offset);
}
- public IEnumerator GetEnumerator ()
+ ///
+ /// Copies the contents of the to the specified array of .
+ ///
+ ///
+ /// An array of that receives the URI prefix strings in the .
+ ///
+ ///
+ /// An that contains the zero-based index in at which copying begins.
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
+ public void CopyTo (string [] array, int offset)
{
- return prefixes.GetEnumerator ();
+ listener.CheckDisposed ();
+ prefixes.CopyTo (array, offset);
}
- IEnumerator IEnumerable.GetEnumerator ()
+ ///
+ /// Gets an object that can be used to iterate through the .
+ ///
+ ///
+ /// An object that implements the IEnumerator<string> interface and provides access to
+ /// the URI prefix strings in the .
+ ///
+ public IEnumerator GetEnumerator ()
{
return prefixes.GetEnumerator ();
}
+ ///
+ /// Removes the specified from the list of prefixes in the .
+ ///
+ ///
+ /// true if the was found in the
+ /// and removed; otherwise, false.
+ ///
+ ///
+ /// A that contains a URI prefix to remove.
+ ///
+ ///
+ /// is .
+ ///
+ ///
+ /// The associated with this is closed.
+ ///
public bool Remove (string uriPrefix)
{
listener.CheckDisposed ();
@@ -123,5 +257,7 @@ namespace WebSocketSharp.Net {
return result;
}
+
+ #endregion
}
}
diff --git a/websocket-sharp/Net/HttpStreamAsyncResult.cs b/websocket-sharp/Net/HttpStreamAsyncResult.cs
index 6ae5e6f0..a9f2f094 100644
--- a/websocket-sharp/Net/HttpStreamAsyncResult.cs
+++ b/websocket-sharp/Net/HttpStreamAsyncResult.cs
@@ -1,6 +1,6 @@
//
// HttpStreamAsyncResult.cs
-// Copied from System.Net.HttpStreamAsyncResult
+// Copied from System.Net.HttpStreamAsyncResult.cs
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
@@ -28,24 +28,33 @@
//
using System;
-using System.Net;
using System.Threading;
namespace WebSocketSharp.Net {
- class HttpStreamAsyncResult : IAsyncResult
- {
+ class HttpStreamAsyncResult : IAsyncResult {
+
+ #region Private Fields
+
bool completed;
ManualResetEvent handle;
object locker = new object ();
+ #endregion
+
+ #region Internal Fields
+
internal AsyncCallback Callback;
internal int Count;
internal byte [] Buffer;
internal Exception Error;
internal int Offset;
internal object State;
- internal int SynchRead;
+ internal int SyncRead;
+
+ #endregion
+
+ #region Properties
public object AsyncState {
get { return State; }
@@ -63,7 +72,7 @@ namespace WebSocketSharp.Net {
}
public bool CompletedSynchronously {
- get { return (SynchRead == Count); }
+ get { return (SyncRead == Count); }
}
public bool IsCompleted {
@@ -74,6 +83,10 @@ namespace WebSocketSharp.Net {
}
}
+ #endregion
+
+ #region Public Methods
+
public void Complete ()
{
lock (locker) {
@@ -94,5 +107,7 @@ namespace WebSocketSharp.Net {
Error = e;
Complete ();
}
+
+ #endregion
}
}
diff --git a/websocket-sharp/Net/ListenerPrefix.cs b/websocket-sharp/Net/ListenerPrefix.cs
index 41f4d590..57fca953 100644
--- a/websocket-sharp/Net/ListenerPrefix.cs
+++ b/websocket-sharp/Net/ListenerPrefix.cs
@@ -1,6 +1,6 @@
//
// ListenerPrefix.cs
-// Copied from System.ListenerPrefix
+// Copied from System.ListenerPrefix.cs
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
@@ -35,21 +35,36 @@ namespace WebSocketSharp.Net {
sealed class ListenerPrefix {
- IPAddress [] addresses;
- string host;
- string original;
- string path;
- ushort port;
- bool secure;
+ #region Private Fields
+
+ IPAddress [] addresses;
+ string host;
+ string original;
+ string path;
+ ushort port;
+ bool secure;
+
+ #endregion
+
+ #region Public Field
public HttpListener Listener;
+ #endregion
+
+ #region Constructor
+
+ // Must be called after calling ListenerPrefix.CheckUri.
public ListenerPrefix (string prefix)
{
original = prefix;
Parse (prefix);
}
+ #endregion
+
+ #region Properties
+
public IPAddress [] Addresses {
get { return addresses; }
set { addresses = value; }
@@ -71,19 +86,18 @@ namespace WebSocketSharp.Net {
get { return secure; }
}
+ #endregion
+
+ #region Private Method
+
void Parse (string uri)
{
- int default_port = (uri.StartsWith ("http://")) ? 80 : -1;
- if (default_port == -1) {
- default_port = (uri.StartsWith ("https://")) ? 443 : -1;
+ int default_port = (uri.StartsWith ("http://")) ? 80 : 443;
+ if (default_port == 443)
secure = true;
- }
int length = uri.Length;
int start_host = uri.IndexOf (':') + 3;
- if (start_host >= length)
- throw new ArgumentException ("No host specified.");
-
int colon = uri.IndexOf (':', start_host, length - start_host);
int root;
if (colon > 0) {
@@ -95,15 +109,21 @@ namespace WebSocketSharp.Net {
root = uri.IndexOf ('/', start_host, length - start_host);
host = uri.Substring (start_host, root - start_host);
path = uri.Substring (root);
+ port = (ushort) default_port;
}
+
if (path.Length != 1)
path = path.Substring (0, path.Length - 1);
}
+ #endregion
+
+ #region public Methods
+
public static void CheckUri (string uri)
{
if (uri == null)
- throw new ArgumentNullException ("uriPrefix");
+ throw new ArgumentNullException ("uri");
int default_port = (uri.StartsWith ("http://")) ? 80 : -1;
if (default_port == -1)
@@ -140,13 +160,13 @@ namespace WebSocketSharp.Net {
}
if (uri [uri.Length - 1] != '/')
- throw new ArgumentException ("The prefix must end with '/'");
+ throw new ArgumentException ("The prefix must end with '/'.");
}
// Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection.
public override bool Equals (object o)
{
- ListenerPrefix other = o as ListenerPrefix;
+ var other = o as ListenerPrefix;
if (other == null)
return false;
@@ -162,5 +182,7 @@ namespace WebSocketSharp.Net {
{
return original;
}
+
+ #endregion
}
}
diff --git a/websocket-sharp/Net/RequestStream.cs b/websocket-sharp/Net/RequestStream.cs
index 2b08ea40..2af57f6f 100644
--- a/websocket-sharp/Net/RequestStream.cs
+++ b/websocket-sharp/Net/RequestStream.cs
@@ -1,6 +1,6 @@
//
// RequestStream.cs
-// Copied from System.Net.RequestStream
+// Copied from System.Net.RequestStream.cs
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
@@ -29,27 +29,31 @@
using System;
using System.IO;
-using System.Net;
-using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace WebSocketSharp.Net {
- class RequestStream : Stream
- {
+ class RequestStream : Stream {
+
+ #region Fields
+
byte [] buffer;
- int offset;
- int length;
- long remaining_body;
- bool disposed;
- System.IO.Stream stream;
+ bool disposed;
+ int length;
+ int offset;
+ long remaining_body;
+ Stream stream;
+
+ #endregion
- internal RequestStream (System.IO.Stream stream, byte [] buffer, int offset, int length)
+ #region Constructors
+
+ internal RequestStream (Stream stream, byte [] buffer, int offset, int length)
: this (stream, buffer, offset, length, -1)
{
}
- internal RequestStream (System.IO.Stream stream, byte [] buffer, int offset, int length, long contentlength)
+ internal RequestStream (Stream stream, byte [] buffer, int offset, int length, long contentlength)
{
this.stream = stream;
this.buffer = buffer;
@@ -58,6 +62,10 @@ namespace WebSocketSharp.Net {
this.remaining_body = contentlength;
}
+ #endregion
+
+ #region Properties
+
public override bool CanRead {
get { return true; }
}
@@ -79,33 +87,30 @@ namespace WebSocketSharp.Net {
set { throw new NotSupportedException (); }
}
+ #endregion
- public override void Close ()
- {
- disposed = true;
- }
-
- public override void Flush ()
- {
- }
+ #region Private Method
-
// Returns 0 if we can keep reading from the base stream,
// > 0 if we read something from the buffer.
// -1 if we had a content length set and we finished reading that many bytes.
- int FillFromBuffer (byte [] buffer, int off, int count)
+ int FillFromBuffer (byte [] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (off < 0)
+
+ if (offset < 0)
throw new ArgumentOutOfRangeException ("offset", "< 0");
+
if (count < 0)
throw new ArgumentOutOfRangeException ("count", "< 0");
+
int len = buffer.Length;
- if (off > len)
- throw new ArgumentException ("destination offset is beyond array size");
- if (off > len - count)
- throw new ArgumentException ("Reading would overrun buffer");
+ if (offset > len)
+ throw new ArgumentException ("Destination offset is beyond array size.");
+
+ if (offset > len - count)
+ throw new ArgumentException ("Reading would overrun buffer.");
if (this.remaining_body == 0)
return -1;
@@ -120,51 +125,38 @@ namespace WebSocketSharp.Net {
if (this.offset > this.buffer.Length - size) {
size = Math.Min (size, this.buffer.Length - this.offset);
}
+
if (size == 0)
return 0;
- Buffer.BlockCopy (this.buffer, this.offset, buffer, off, size);
+ Buffer.BlockCopy (this.buffer, this.offset, buffer, offset, size);
this.offset += size;
this.length -= size;
if (this.remaining_body > 0)
remaining_body -= size;
+
return size;
}
- public override int Read ([In,Out] byte[] buffer, int offset, int count)
- {
- if (disposed)
- throw new ObjectDisposedException (typeof (RequestStream).ToString ());
+ #endregion
- // Call FillFromBuffer to check for buffer boundaries even when remaining_body is 0
- int nread = FillFromBuffer (buffer, offset, count);
- if (nread == -1) { // No more bytes available (Content-Length)
- return 0;
- } else if (nread > 0) {
- return nread;
- }
+ #region Public Methods
- nread = stream.Read (buffer, offset, count);
- if (nread > 0 && remaining_body > 0)
- remaining_body -= nread;
- return nread;
- }
-
- public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
- AsyncCallback cback, object state)
+ public override IAsyncResult BeginRead (
+ byte [] buffer, int offset, int count, AsyncCallback cback, object state)
{
if (disposed)
- throw new ObjectDisposedException (typeof (RequestStream).ToString ());
+ throw new ObjectDisposedException (GetType ().ToString ());
int nread = FillFromBuffer (buffer, offset, count);
if (nread > 0 || nread == -1) {
- HttpStreamAsyncResult ares = new HttpStreamAsyncResult ();
+ var ares = new HttpStreamAsyncResult ();
ares.Buffer = buffer;
ares.Offset = offset;
ares.Count = count;
ares.Callback = cback;
ares.State = state;
- ares.SynchRead = nread;
+ ares.SyncRead = nread;
ares.Complete ();
return ares;
}
@@ -173,55 +165,89 @@ namespace WebSocketSharp.Net {
// for HTTP pipelining
if (remaining_body >= 0 && count > remaining_body)
count = (int) Math.Min (Int32.MaxValue, remaining_body);
+
return stream.BeginRead (buffer, offset, count, cback, state);
}
+ public override IAsyncResult BeginWrite (
+ byte [] buffer, int offset, int count, AsyncCallback cback, object state)
+ {
+ throw new NotSupportedException ();
+ }
+
+ public override void Close ()
+ {
+ disposed = true;
+ }
+
public override int EndRead (IAsyncResult ares)
{
if (disposed)
- throw new ObjectDisposedException (typeof (RequestStream).ToString ());
+ throw new ObjectDisposedException (GetType ().ToString ());
if (ares == null)
- throw new ArgumentNullException ("async_result");
+ throw new ArgumentNullException ("ares");
if (ares is HttpStreamAsyncResult) {
- HttpStreamAsyncResult r = (HttpStreamAsyncResult) ares;
+ var ares_ = (HttpStreamAsyncResult) ares;
if (!ares.IsCompleted)
ares.AsyncWaitHandle.WaitOne ();
- return r.SynchRead;
+
+ return ares_.SyncRead;
}
// Close on exception?
int nread = stream.EndRead (ares);
if (remaining_body > 0 && nread > 0)
remaining_body -= nread;
+
return nread;
}
- public override long Seek (long offset, SeekOrigin origin)
+ public override void EndWrite (IAsyncResult async_result)
{
throw new NotSupportedException ();
}
- public override void SetLength (long value)
+ public override void Flush ()
{
- throw new NotSupportedException ();
}
- public override void Write (byte[] buffer, int offset, int count)
+ public override int Read ([In,Out] byte[] buffer, int offset, int count)
+ {
+ if (disposed)
+ throw new ObjectDisposedException (GetType () .ToString ());
+
+ // Call FillFromBuffer to check for buffer boundaries even when remaining_body is 0
+ int nread = FillFromBuffer (buffer, offset, count);
+ if (nread == -1) { // No more bytes available (Content-Length)
+ return 0;
+ } else if (nread > 0) {
+ return nread;
+ }
+
+ nread = stream.Read (buffer, offset, count);
+ if (nread > 0 && remaining_body > 0)
+ remaining_body -= nread;
+
+ return nread;
+ }
+
+ public override long Seek (long offset, SeekOrigin origin)
{
throw new NotSupportedException ();
}
- public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
- AsyncCallback cback, object state)
+ public override void SetLength (long value)
{
throw new NotSupportedException ();
}
- public override void EndWrite (IAsyncResult async_result)
+ public override void Write (byte[] buffer, int offset, int count)
{
throw new NotSupportedException ();
}
+
+ #endregion
}
}
diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll
index 8f734496..ada75c22 100755
Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ
diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb
index 1cd40672..7cc96a4b 100644
Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ
diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll
index 8525e1b8..48e4cc15 100755
Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ
diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml
index 6785e014..a18fc062 100644
--- a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml
+++ b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml
@@ -1683,6 +1683,140 @@
An that contains an error code.
+
+
+ Provides the collection used to store the URI prefixes for the .
+
+
+
+
+ Gets the number of prefixes contained in the .
+
+
+ A that contains the number of prefixes.
+
+
+
+
+ Gets a value indicating whether access to the is read-only.
+
+
+ Always returns false.
+
+
+
+
+ Gets a value indicating whether access to the is synchronized.
+
+
+ Always returns false.
+
+
+
+
+ Gets an object that can be used to iterate through the .
+
+
+ An object that implements the interface and provides access to
+ the URI prefix strings in the .
+
+
+
+
+ Adds the specified to the .
+
+
+ A that contains a URI prefix to add.
+
+
+ is .
+
+
+ The associated with this is closed.
+
+
+
+
+ Removes all URI prefixes from the .
+
+
+ The associated with this is closed.
+
+
+
+
+ Returns a value indicating whether the contains
+ the specified .
+
+
+ true if the contains the specified ;
+ otherwise, false.
+
+
+ A that contains a URI prefix to test.
+
+
+ is .
+
+
+ The associated with this is closed.
+
+
+
+
+ Copies the contents of the to the specified .
+
+
+ An that receives the URI prefix strings in the .
+
+
+ An that contains the zero-based index in at which copying begins.
+
+
+ The associated with this is closed.
+
+
+
+
+ Copies the contents of the to the specified array of .
+
+
+ An array of that receives the URI prefix strings in the .
+
+
+ An that contains the zero-based index in at which copying begins.
+
+
+ The associated with this is closed.
+
+
+
+
+ Gets an object that can be used to iterate through the .
+
+
+ An object that implements the IEnumerator<string> interface and provides access to
+ the URI prefix strings in the .
+
+
+
+
+ Removes the specified from the list of prefixes in the .
+
+
+ true if the was found in the
+ and removed; otherwise, false.
+
+
+ A that contains a URI prefix to remove.
+
+
+ is .
+
+
+ The associated with this is closed.
+
+
Decodes an HTML-encoded string and returns the decoded string.
diff --git a/websocket-sharp/doc/html/WebSocketSharp.Net/HttpListenerPrefixCollection.html b/websocket-sharp/doc/html/WebSocketSharp.Net/HttpListenerPrefixCollection.html
index 67ad6e82..e681f82f 100644
--- a/websocket-sharp/doc/html/WebSocketSharp.Net/HttpListenerPrefixCollection.html
+++ b/websocket-sharp/doc/html/WebSocketSharp.Net/HttpListenerPrefixCollection.html
@@ -207,8 +207,8 @@
HttpListenerPrefixCollection Class
- Documentation for this section has not yet been entered.
-
+ Provides the collection used to store the URI prefixes for the WebSocketSharp.Net.HttpListener.
+
@@ -282,7 +288,9 @@
Add
- (string)Documentation for this section has not yet been entered. |
+ (string)
+ Adds the specified uriPrefix to the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
|
@@ -292,7 +300,9 @@
|
Clear
- ()Documentation for this section has not yet been entered. |
+ ()
+ Removes all URI prefixes from the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
|
@@ -302,7 +312,10 @@
|
Contains
- (string) : boolDocumentation for this section has not yet been entered. |
+ (string) : bool
+ Returns a value indicating whether the WebSocketSharp.Net.HttpListenerPrefixCollection contains
+ the specified uriPrefix.
+
|
@@ -312,7 +325,9 @@
|
CopyTo
- (Array, int)Documentation for this section has not yet been entered. |
+ (Array, int)
+ Copies the contents of the WebSocketSharp.Net.HttpListenerPrefixCollection to the specified Array.
+
|
@@ -322,7 +337,9 @@
|
CopyTo
- (string[], int)Documentation for this section has not yet been entered. |
+ (string[], int)
+ Copies the contents of the WebSocketSharp.Net.HttpListenerPrefixCollection to the specified array of string.
+
|
@@ -332,7 +349,9 @@
|
GetEnumerator
- () : IEnumerator<string>Documentation for this section has not yet been entered. |
+ () : IEnumerator<string>
+ Gets an object that can be used to iterate through the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
|
@@ -342,7 +361,9 @@
|
Remove
- (string) : boolDocumentation for this section has not yet been entered. |
+ (string) : bool
+ Removes the specified uriPrefix from the list of prefixes in the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
@@ -362,8 +383,8 @@
- Documentation for this section has not yet been entered.
- |
+ Gets an object that can be used to iterate through the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
@@ -406,8 +427,8 @@
Add Method
- Documentation for this section has not yet been entered.
-
+ Adds the specified uriPrefix to the WebSocketSharp.Net.HttpListenerPrefixCollection.
+
Syntax
Parameters
@@ -417,10 +438,35 @@
uriPrefix
- Documentation for this section has not yet been entered.
-
+ A string that contains a URI prefix to add.
+
+ Exceptions
+
+
+
Remarks