diff --git a/.vs/WebSocket4Net/v15/Server/sqlite3/db.lock b/.vs/WebSocket4Net/v15/Server/sqlite3/db.lock new file mode 100644 index 00000000..e69de29b diff --git a/.vs/WebSocket4Net/v15/Server/sqlite3/storage.ide b/.vs/WebSocket4Net/v15/Server/sqlite3/storage.ide new file mode 100644 index 00000000..da808af7 Binary files /dev/null and b/.vs/WebSocket4Net/v15/Server/sqlite3/storage.ide differ diff --git a/WebSocket4Net/Action.cs b/WebSocket4Net/Action.cs index 7444c82d..278095cc 100644 --- a/WebSocket4Net/Action.cs +++ b/WebSocket4Net/Action.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace System +namespace System { public delegate void Action(T1 t1, T2 t2); public delegate void Action(T1 t1, T2 t2, T3 t3); public delegate void Action(T1 t1, T2 t2, T3 t3, T4 t4); -} +} \ No newline at end of file diff --git a/WebSocket4Net/ClosedEventArgs.cs b/WebSocket4Net/ClosedEventArgs.cs index f5811233..ac9a3f75 100644 --- a/WebSocket4Net/ClosedEventArgs.cs +++ b/WebSocket4Net/ClosedEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace WebSocket4Net { @@ -37,4 +34,4 @@ public ClosedEventArgs(short code, string reason) Reason = reason; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/BadRequest.cs b/WebSocket4Net/Command/BadRequest.cs index f23134b4..ffdf8b61 100644 --- a/WebSocket4Net/Command/BadRequest.cs +++ b/WebSocket4Net/Command/BadRequest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; namespace WebSocket4Net.Command { @@ -68,4 +67,4 @@ public override string Name get { return OpCode.BadRequest.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Binary.cs b/WebSocket4Net/Command/Binary.cs index a0375ab5..274526af 100644 --- a/WebSocket4Net/Command/Binary.cs +++ b/WebSocket4Net/Command/Binary.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; - -namespace WebSocket4Net.Command +namespace WebSocket4Net.Command { public class Binary : WebSocketCommandBase { @@ -17,4 +12,4 @@ public override string Name get { return OpCode.Binary.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Close.cs b/WebSocket4Net/Command/Close.cs index 58ea8487..e51c824b 100644 --- a/WebSocket4Net/Command/Close.cs +++ b/WebSocket4Net/Command/Close.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; - -namespace WebSocket4Net.Command +namespace WebSocket4Net.Command { public class Close : WebSocketCommandBase { @@ -30,4 +25,4 @@ public override string Name get { return OpCode.Close.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Handshake.cs b/WebSocket4Net/Command/Handshake.cs index 43d190b2..9c7f5f47 100644 --- a/WebSocket4Net/Command/Handshake.cs +++ b/WebSocket4Net/Command/Handshake.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net.Command { @@ -25,4 +23,4 @@ public override string Name get { return OpCode.Handshake.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Ping.cs b/WebSocket4Net/Command/Ping.cs index 40a80155..28ee9c6c 100644 --- a/WebSocket4Net/Command/Ping.cs +++ b/WebSocket4Net/Command/Ping.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net.Command { @@ -17,4 +15,4 @@ public override string Name get { return OpCode.Ping.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Pong.cs b/WebSocket4Net/Command/Pong.cs index 2e36dad8..01423ff0 100644 --- a/WebSocket4Net/Command/Pong.cs +++ b/WebSocket4Net/Command/Pong.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Command { @@ -18,4 +15,4 @@ public override string Name get { return OpCode.Pong.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/Text.cs b/WebSocket4Net/Command/Text.cs index 168c173b..b5204eb1 100644 --- a/WebSocket4Net/Command/Text.cs +++ b/WebSocket4Net/Command/Text.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; - -namespace WebSocket4Net.Command +namespace WebSocket4Net.Command { public class Text : WebSocketCommandBase { @@ -17,4 +12,4 @@ public override string Name get { return OpCode.Text.ToString(); } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Command/WebSocketCommandBase.cs b/WebSocket4Net/Command/WebSocketCommandBase.cs index 61995082..601def12 100644 --- a/WebSocket4Net/Command/WebSocketCommandBase.cs +++ b/WebSocket4Net/Command/WebSocketCommandBase.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; -using WebSocket4Net.Common; +using WebSocket4Net.Common; namespace WebSocket4Net.Command { @@ -12,4 +8,4 @@ public abstract class WebSocketCommandBase : ICommand + internal class ArraySegmentEx { public ArraySegmentEx(T[] array, int offset, int count) { @@ -12,6 +8,7 @@ public ArraySegmentEx(T[] array, int offset, int count) Offset = offset; Count = count; } + /// /// Gets the array. /// @@ -31,4 +28,4 @@ public ArraySegmentEx(T[] array, int offset, int count) public int To { get; set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/ArraySegmentList.cs b/WebSocket4Net/Common/ArraySegmentList.cs index 875b0b13..9484a1fa 100644 --- a/WebSocket4Net/Common/ArraySegmentList.cs +++ b/WebSocket4Net/Common/ArraySegmentList.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Common { @@ -263,7 +262,7 @@ internal ArraySegmentEx QuickSearchSegment(int from, int to, int index, out i } } - #endregion + #endregion IList Members #region ICollection Members @@ -302,7 +301,7 @@ public bool Remove(T item) throw new NotSupportedException(); } - #endregion + #endregion ICollection Members #region IEnumerable Members @@ -311,7 +310,7 @@ public IEnumerator GetEnumerator() throw new NotSupportedException(); } - #endregion + #endregion IEnumerable Members #region IEnumerable Members @@ -320,7 +319,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() throw new NotSupportedException(); } - #endregion + #endregion IEnumerable Members public void RemoveSegmentAt(int index) { @@ -331,7 +330,7 @@ public void RemoveSegmentAt(int index) m_PrevSegment = null; - //the removed item is not the the last item + //the removed item is not the the last item if (index != m_Segments.Count) { for (int i = index; i < m_Segments.Count; i++) @@ -609,4 +608,4 @@ public void DecodeMask(byte[] mask, int offset, int length) } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/BinaryCommandInfo.cs b/WebSocket4Net/Common/BinaryCommandInfo.cs index bdca71b7..3aa85c5b 100644 --- a/WebSocket4Net/Common/BinaryCommandInfo.cs +++ b/WebSocket4Net/Common/BinaryCommandInfo.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public class BinaryCommandInfo : CommandInfo { public BinaryCommandInfo(string key, byte[] data) : base(key, data) { - } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/CommandInfo.cs b/WebSocket4Net/Common/CommandInfo.cs index f57f119c..d7f9bca2 100644 --- a/WebSocket4Net/Common/CommandInfo.cs +++ b/WebSocket4Net/Common/CommandInfo.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public abstract class CommandInfo : ICommandInfo { @@ -16,12 +12,12 @@ public CommandInfo(string key, TCommandData data) public TCommandData Data { get; private set; } - #endregion + #endregion ICommandInfo Members #region ICommandInfo Members public string Key { get; private set; } - #endregion + #endregion ICommandInfo Members } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/DelegateCommand.cs b/WebSocket4Net/Common/DelegateCommand.cs index 507bd989..c7ecd951 100644 --- a/WebSocket4Net/Common/DelegateCommand.cs +++ b/WebSocket4Net/Common/DelegateCommand.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public delegate void CommandDelegate(TClientSession session, TCommandInfo commandInfo); - class DelegateCommand : ICommand + internal class DelegateCommand : ICommand where TClientSession : IClientSession where TCommandInfo : ICommandInfo { @@ -26,4 +21,4 @@ public void ExecuteCommand(TClientSession session, TCommandInfo commandInfo) public string Name { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/IClientCommandReader.cs b/WebSocket4Net/Common/IClientCommandReader.cs index f58e8280..7619f189 100644 --- a/WebSocket4Net/Common/IClientCommandReader.cs +++ b/WebSocket4Net/Common/IClientCommandReader.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public interface IClientCommandReader where TCommandInfo : ICommandInfo @@ -11,4 +7,4 @@ public interface IClientCommandReader IClientCommandReader NextCommandReader { get; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/ICommand.cs b/WebSocket4Net/Common/ICommand.cs index 54499496..0a4f77b7 100644 --- a/WebSocket4Net/Common/ICommand.cs +++ b/WebSocket4Net/Common/ICommand.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public interface ICommand { @@ -14,4 +10,4 @@ public interface ICommand : ICommand { void ExecuteCommand(TSession session, TCommandInfo commandInfo); } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/ICommandInfo.cs b/WebSocket4Net/Common/ICommandInfo.cs index dbfdc4ce..e8e30ea3 100644 --- a/WebSocket4Net/Common/ICommandInfo.cs +++ b/WebSocket4Net/Common/ICommandInfo.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public interface ICommandInfo { @@ -13,4 +9,4 @@ public interface ICommandInfo : ICommandInfo { TCommandData Data { get; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Common/StringCommandInfo.cs b/WebSocket4Net/Common/StringCommandInfo.cs index ba4505ed..da9bb179 100644 --- a/WebSocket4Net/Common/StringCommandInfo.cs +++ b/WebSocket4Net/Common/StringCommandInfo.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Common +namespace WebSocket4Net.Common { public class StringCommandInfo : CommandInfo { @@ -27,4 +23,4 @@ public string this[int index] get { return Parameters[index]; } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/DataReceivedEventArgs.cs b/WebSocket4Net/DataReceivedEventArgs.cs index 47754222..07e07b66 100644 --- a/WebSocket4Net/DataReceivedEventArgs.cs +++ b/WebSocket4Net/DataReceivedEventArgs.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net { @@ -13,4 +11,4 @@ public DataReceivedEventArgs(byte[] data) public byte[] Data { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/ExtensionAttribute.cs b/WebSocket4Net/ExtensionAttribute.cs index 56b38af0..8a7302ad 100644 --- a/WebSocket4Net/ExtensionAttribute.cs +++ b/WebSocket4Net/ExtensionAttribute.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace System.Runtime.CompilerServices +namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Method)] internal sealed class ExtensionAttribute : Attribute { - public ExtensionAttribute() { } + public ExtensionAttribute() + { + } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Extensions.cs b/WebSocket4Net/Extensions.cs index 40c7b4c6..e4c82f46 100644 --- a/WebSocket4Net/Extensions.cs +++ b/WebSocket4Net/Extensions.cs @@ -3,17 +3,16 @@ using System.Text; using System.IO; using System.Linq; -using System.Reflection; -using SuperSocket.ClientEngine; #if !NETFX_CORE + using System.Security.Cryptography; + #else using Windows.Security.Cryptography; using Windows.Security.Cryptography.Core; #endif - namespace WebSocket4Net { public static partial class Extensions @@ -135,7 +134,6 @@ public static TValue GetValue(this IDictionary valueCont typeof(Guid) }; - internal static bool IsSimpleType(this Type type) { #if NETFX_CORE || NETCORE @@ -177,7 +175,6 @@ public static byte[] ComputeMD5Hash(this byte[] source) #else return MD5.Create().ComputeHash(source); #endif - } public static string CalculateChallenge(this string source) @@ -193,7 +190,6 @@ public static string CalculateChallenge(this string source) #else return Convert.ToBase64String(SHA1.Create().ComputeHash(ASCIIEncoding.Instance.GetBytes(source))); #endif - } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/GlobalAssemblyInfo.cs b/WebSocket4Net/GlobalAssemblyInfo.cs index 614084d6..6d137e40 100644 --- a/WebSocket4Net/GlobalAssemblyInfo.cs +++ b/WebSocket4Net/GlobalAssemblyInfo.cs @@ -1,7 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Diagnostics.CodeAnalysis; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("WebSocket4Net")] @@ -10,4 +7,4 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("0.15.1.10")] -[assembly: AssemblyFileVersion("0.15.1.10")] +[assembly: AssemblyFileVersion("0.15.1.10")] \ No newline at end of file diff --git a/WebSocket4Net/IJsonExecutor.cs b/WebSocket4Net/IJsonExecutor.cs index b14a4a2f..c1f9eda7 100644 --- a/WebSocket4Net/IJsonExecutor.cs +++ b/WebSocket4Net/IJsonExecutor.cs @@ -1,13 +1,11 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net { - interface IJsonExecutor + internal interface IJsonExecutor { Type Type { get; } void Execute(JsonWebSocket websocket, string token, object param); } -} +} \ No newline at end of file diff --git a/WebSocket4Net/JsonExecutor.cs b/WebSocket4Net/JsonExecutor.cs index 9bc67248..b95cf546 100644 --- a/WebSocket4Net/JsonExecutor.cs +++ b/WebSocket4Net/JsonExecutor.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net { - abstract class JsonExecutorBase : IJsonExecutor + internal abstract class JsonExecutorBase : IJsonExecutor { public Type Type { @@ -17,7 +15,7 @@ public Type Type public abstract void Execute(JsonWebSocket websocket, string token, object param); } - class JsonExecutor : JsonExecutorBase + internal class JsonExecutor : JsonExecutorBase { private Action m_ExecutorAction; @@ -28,15 +26,15 @@ public JsonExecutor(Action action) public override void Execute(JsonWebSocket websocket, string token, object param) { - #if NETCORE +#if NETCORE m_ExecutorAction.DynamicInvoke(new object[] { param }); - #else - m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { param }); - #endif +#else + m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { param }); +#endif } } - class JsonExecutorWithToken : JsonExecutorBase + internal class JsonExecutorWithToken : JsonExecutorBase { private Action m_ExecutorAction; @@ -47,15 +45,15 @@ public JsonExecutorWithToken(Action action) public override void Execute(JsonWebSocket websocket, string token, object param) { - #if NETCORE +#if NETCORE m_ExecutorAction.DynamicInvoke(new object[] { token, param }); - #else - m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { token, param }); - #endif +#else + m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { token, param }); +#endif } } - class JsonExecutorWithSender : JsonExecutorBase + internal class JsonExecutorWithSender : JsonExecutorBase { private Action m_ExecutorAction; @@ -66,15 +64,15 @@ public JsonExecutorWithSender(Action action) public override void Execute(JsonWebSocket websocket, string token, object param) { - #if NETCORE +#if NETCORE m_ExecutorAction.DynamicInvoke(new object[] { websocket, param }); - #else - m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, param }); - #endif +#else + m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, param }); +#endif } } - class JsonExecutorFull : JsonExecutorBase + internal class JsonExecutorFull : JsonExecutorBase { private Action m_ExecutorAction; @@ -85,15 +83,15 @@ public JsonExecutorFull(Action action) public override void Execute(JsonWebSocket websocket, string token, object param) { - #if NETCORE +#if NETCORE m_ExecutorAction.DynamicInvoke(new object[] { websocket, token, param }); - #else - m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, token, param }); - #endif +#else + m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, token, param }); +#endif } } - class JsonExecutorWithSenderAndState : JsonExecutorBase + internal class JsonExecutorWithSenderAndState : JsonExecutorBase { private Action m_ExecutorAction; @@ -107,11 +105,11 @@ public JsonExecutorWithSenderAndState(Action action, o public override void Execute(JsonWebSocket websocket, string token, object param) { - #if NETCORE +#if NETCORE m_ExecutorAction.DynamicInvoke(new object[] { websocket, param, m_State }); - #else - m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, param, m_State }); - #endif +#else + m_ExecutorAction.Method.Invoke(m_ExecutorAction.Target, new object[] { websocket, param, m_State }); +#endif } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/JsonWebSocket.DataContractJson.cs b/WebSocket4Net/JsonWebSocket.DataContractJson.cs index 53510036..59dc7617 100644 --- a/WebSocket4Net/JsonWebSocket.DataContractJson.cs +++ b/WebSocket4Net/JsonWebSocket.DataContractJson.cs @@ -1,7 +1,7 @@ using System; using System.IO; -using System.Text; using System.Runtime.Serialization.Json; +using System.Text; namespace WebSocket4Net { @@ -42,4 +42,4 @@ protected virtual object DeserializeObject(string json, Type type) }; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/JsonWebSocket.JsonNotSet.cs b/WebSocket4Net/JsonWebSocket.JsonNotSet.cs index 901cf884..f6175e3c 100644 --- a/WebSocket4Net/JsonWebSocket.JsonNotSet.cs +++ b/WebSocket4Net/JsonWebSocket.JsonNotSet.cs @@ -1,6 +1,4 @@ using System; -using System.IO; -using System.Text; namespace WebSocket4Net { @@ -52,4 +50,4 @@ protected virtual object DeserializeObject(string json, Type type) return deserializer(json, type); } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/JsonWebSocket.Net.cs b/WebSocket4Net/JsonWebSocket.Net.cs index 29574a6b..8b645117 100644 --- a/WebSocket4Net/JsonWebSocket.Net.cs +++ b/WebSocket4Net/JsonWebSocket.Net.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using SuperSocket.ClientEngine; - -namespace WebSocket4Net +namespace WebSocket4Net { public partial class JsonWebSocket { @@ -16,4 +10,4 @@ public SecurityOption Security get { return m_WebSocket.Security; } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/JsonWebSocket.cs b/WebSocket4Net/JsonWebSocket.cs index 6644e702..5a8ef274 100644 --- a/WebSocket4Net/JsonWebSocket.cs +++ b/WebSocket4Net/JsonWebSocket.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Net.Sockets; -using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net { @@ -46,49 +43,41 @@ public WebSocketState State public JsonWebSocket(string uri) : this(uri, string.Empty) { - } public JsonWebSocket(string uri, WebSocketVersion version) : this(uri, string.Empty, null, version) { - } public JsonWebSocket(string uri, string subProtocol) : this(uri, subProtocol, null, WebSocketVersion.None) { - } public JsonWebSocket(string uri, List> cookies) : this(uri, string.Empty, cookies, WebSocketVersion.None) { - } public JsonWebSocket(string uri, string subProtocol, List> cookies) : this(uri, subProtocol, cookies, WebSocketVersion.None) { - } public JsonWebSocket(string uri, string subProtocol, WebSocketVersion version) : this(uri, subProtocol, null, version) { - } public JsonWebSocket(string uri, string subProtocol, List> cookies, WebSocketVersion version) : this(uri, subProtocol, cookies, null, string.Empty, string.Empty, version) { - } public JsonWebSocket(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, WebSocketVersion version) : this(uri, subProtocol, cookies, customHeaderItems, userAgent, string.Empty, version) { - } public JsonWebSocket(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, string origin, WebSocketVersion version) @@ -155,7 +144,7 @@ public event EventHandler Error remove { m_Error -= value; } } - void m_WebSocket_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e) + private void m_WebSocket_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e) { if (m_Error == null) return; @@ -171,7 +160,7 @@ public event EventHandler Opened remove { m_Opened -= value; } } - void m_WebSocket_Opened(object sender, EventArgs e) + private void m_WebSocket_Opened(object sender, EventArgs e) { if (m_Opened == null) return; @@ -179,7 +168,7 @@ void m_WebSocket_Opened(object sender, EventArgs e) m_Opened(this, e); } - void m_WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e) + private void m_WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e) { if (string.IsNullOrEmpty(e.Message)) return; @@ -249,7 +238,7 @@ public event EventHandler Closed remove { m_Closed -= value; } } - void m_WebSocket_Closed(object sender, EventArgs e) + private void m_WebSocket_Closed(object sender, EventArgs e) { if (m_Closed == null) return; @@ -268,7 +257,6 @@ public void On(string name, Action executor) RegisterExecutor(name, string.Empty, new JsonExecutor(executor)); } - /// /// Registers the message handler. /// @@ -374,7 +362,7 @@ public string Query(string name, object content, Action(name, content, new JsonExecutorWithSenderAndState(executor, state)); } - string Query(string name, object content, IJsonExecutor executor) + private string Query(string name, object content, IJsonExecutor executor) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); @@ -398,7 +386,7 @@ string Query(string name, object content, IJsonExecutor executor) private Dictionary m_ExecutorDict = new Dictionary(StringComparer.OrdinalIgnoreCase); - void RegisterExecutor(string name, string token, IJsonExecutor executor) + private void RegisterExecutor(string name, string token, IJsonExecutor executor) { lock (m_ExecutorDict) { @@ -409,7 +397,7 @@ void RegisterExecutor(string name, string token, IJsonExecutor executor) } } - IJsonExecutor GetExecutor(string name, string token) + private IJsonExecutor GetExecutor(string name, string token) { string key = name; bool removeExecutor = false; @@ -463,4 +451,4 @@ protected virtual void Dispose(bool disposing) Dispose(false); } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/MessageReceivedEventArgs.cs b/WebSocket4Net/MessageReceivedEventArgs.cs index 79ce856c..555ca9b8 100644 --- a/WebSocket4Net/MessageReceivedEventArgs.cs +++ b/WebSocket4Net/MessageReceivedEventArgs.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace WebSocket4Net { @@ -13,4 +11,4 @@ public MessageReceivedEventArgs(string message) public string Message { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/OpCode.cs b/WebSocket4Net/OpCode.cs index 55bb5d0f..32964c94 100644 --- a/WebSocket4Net/OpCode.cs +++ b/WebSocket4Net/OpCode.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net +namespace WebSocket4Net { public class OpCode { @@ -14,4 +10,4 @@ public class OpCode public const int Pong = 10; public const int BadRequest = 400; } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Properties/AssemblyInfo.Net20.cs b/WebSocket4Net/Properties/AssemblyInfo.Net20.cs index bb04c16b..89330eee 100644 --- a/WebSocket4Net/Properties/AssemblyInfo.Net20.cs +++ b/WebSocket4Net/Properties/AssemblyInfo.Net20.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("WebSocket4Net for .NET 2.0")] diff --git a/WebSocket4Net/Properties/AssemblyInfo.Net35.cs b/WebSocket4Net/Properties/AssemblyInfo.Net35.cs index ecce97dc..87ce4fb9 100644 --- a/WebSocket4Net/Properties/AssemblyInfo.Net35.cs +++ b/WebSocket4Net/Properties/AssemblyInfo.Net35.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("WebSocket4Net for .NET 3.5")] diff --git a/WebSocket4Net/Properties/AssemblyInfo.Net40.cs b/WebSocket4Net/Properties/AssemblyInfo.Net40.cs index 94cc59e6..5084e675 100644 --- a/WebSocket4Net/Properties/AssemblyInfo.Net40.cs +++ b/WebSocket4Net/Properties/AssemblyInfo.Net40.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("WebSocket4Net for .NET 4.0/Mono 2.10+")] diff --git a/WebSocket4Net/Properties/AssemblyInfo.Net45.cs b/WebSocket4Net/Properties/AssemblyInfo.Net45.cs index d7f7fd73..64f9c22d 100644 --- a/WebSocket4Net/Properties/AssemblyInfo.Net45.cs +++ b/WebSocket4Net/Properties/AssemblyInfo.Net45.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("WebSocket4Net for .NET 4.5")] diff --git a/WebSocket4Net/Protocol/CloseStatusCodeHybi10.cs b/WebSocket4Net/Protocol/CloseStatusCodeHybi10.cs index d425c9cf..0b34e2db 100644 --- a/WebSocket4Net/Protocol/CloseStatusCodeHybi10.cs +++ b/WebSocket4Net/Protocol/CloseStatusCodeHybi10.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol +namespace WebSocket4Net.Protocol { public class CloseStatusCodeHybi10 : ICloseStatusCode { @@ -33,4 +29,4 @@ public CloseStatusCodeHybi10() public short TLSHandshakeFailure { get; private set; } public short NoStatusCode { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/CloseStatusCodeRfc6455.cs b/WebSocket4Net/Protocol/CloseStatusCodeRfc6455.cs index 4e0cd4fd..0d1cef20 100644 --- a/WebSocket4Net/Protocol/CloseStatusCodeRfc6455.cs +++ b/WebSocket4Net/Protocol/CloseStatusCodeRfc6455.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol +namespace WebSocket4Net.Protocol { public class CloseStatusCodeRfc6455 : ICloseStatusCode { @@ -32,4 +28,4 @@ public CloseStatusCodeRfc6455() public short TLSHandshakeFailure { get; private set; } public short NoStatusCode { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi00DataReader.cs b/WebSocket4Net/Protocol/DraftHybi00DataReader.cs index 0aa86f25..16620243 100644 --- a/WebSocket4Net/Protocol/DraftHybi00DataReader.cs +++ b/WebSocket4Net/Protocol/DraftHybi00DataReader.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Text; namespace WebSocket4Net.Protocol { - class DraftHybi00DataReader : ReaderBase + internal class DraftHybi00DataReader : ReaderBase { private byte? m_Type; private int m_TempLength; @@ -15,7 +13,6 @@ class DraftHybi00DataReader : ReaderBase public DraftHybi00DataReader(ReaderBase previousCommandReader) : base(previousCommandReader) { - } public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offset, int length, out int left) @@ -123,7 +120,7 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse } } - void Reset(bool clearBuffer) + private void Reset(bool clearBuffer) { m_Type = null; m_Length = null; @@ -133,4 +130,4 @@ void Reset(bool clearBuffer) BufferSegments.ClearSegements(); } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi00HandshakeReader.cs b/WebSocket4Net/Protocol/DraftHybi00HandshakeReader.cs index c282f64f..dffafa37 100644 --- a/WebSocket4Net/Protocol/DraftHybi00HandshakeReader.cs +++ b/WebSocket4Net/Protocol/DraftHybi00HandshakeReader.cs @@ -1,28 +1,23 @@ using System; -using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Protocol { - class DraftHybi00HandshakeReader : HandshakeReader + internal class DraftHybi00HandshakeReader : HandshakeReader { //-1 indicate response header has not been received private int m_ReceivedChallengeLength = -1; + private int m_ExpectedChallengeLength = 16; private WebSocketCommandInfo m_HandshakeCommand = null; private byte[] m_Challenges = new byte[16]; - - public DraftHybi00HandshakeReader(WebSocket websocket) : base(websocket) { - } - void SetDataReader() + private void SetDataReader() { NextCommandReader = new DraftHybi00DataReader(this); } @@ -77,7 +72,7 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse else { int receivedTotal = m_ReceivedChallengeLength + length; - + if (receivedTotal < m_ExpectedChallengeLength) { Buffer.BlockCopy(readBuffer, offset, m_Challenges, m_ReceivedChallengeLength, length); @@ -105,4 +100,4 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi00Processor.cs b/WebSocket4Net/Protocol/DraftHybi00Processor.cs index 4f724576..c536d7f1 100644 --- a/WebSocket4Net/Protocol/DraftHybi00Processor.cs +++ b/WebSocket4Net/Protocol/DraftHybi00Processor.cs @@ -3,19 +3,17 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Protocol { /// /// http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00 /// - class DraftHybi00Processor : ProtocolProcessorBase + internal class DraftHybi00Processor : ProtocolProcessorBase { public DraftHybi00Processor() : base(WebSocketVersion.DraftHybi00, new CloseStatusCodeHybi10()) { - } private static List m_CharLib = new List(); @@ -51,7 +49,6 @@ public override ReaderBase CreateHandshakeReader(WebSocket websocket) private const string m_Error_ChallengeNotMatch = "challenge doesn't match"; private const string m_Error_InvalidHandshake = "invalid handshake"; - public override bool VerifyHandshake(WebSocket websocket, WebSocketCommandInfo handshakeInfo, out string description) { var challenge = handshakeInfo.Data; @@ -143,7 +140,6 @@ public override void SendHandshake(WebSocket websocket) if (websocket.HttpConnectProxy == null) { - #if SILVERLIGHT handshakeBuilder.AppendFormatWithCrCf("GET {0} HTTP/1.1", websocket.TargetUri.GetPathAndQuery()); #else @@ -162,7 +158,7 @@ public override void SendHandshake(WebSocket websocket) handshakeBuilder.Append("Sec-WebSocket-Key1: "); handshakeBuilder.AppendWithCrCf(secKey1); handshakeBuilder.Append("Sec-WebSocket-Key2: "); - handshakeBuilder.AppendWithCrCf(secKey2); + handshakeBuilder.AppendWithCrCf(secKey2); handshakeBuilder.Append("Origin: "); handshakeBuilder.AppendWithCrCf(string.IsNullOrEmpty(websocket.Origin) ? websocket.TargetUri.Host : websocket.Origin); @@ -255,7 +251,7 @@ private byte[] GenerateSecKey(int totalLen) var pos = 0; for (int i = 0; i < spaceLen; i++) - source[pos++] = (byte)' '; + source[pos++] = (byte)' '; for (int i = 0; i < charLen; i++) { @@ -280,4 +276,4 @@ public override bool SupportPingPong get { return false; } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi10DataReader.cs b/WebSocket4Net/Protocol/DraftHybi10DataReader.cs index e4d14d40..fe44ff43 100644 --- a/WebSocket4Net/Protocol/DraftHybi10DataReader.cs +++ b/WebSocket4Net/Protocol/DraftHybi10DataReader.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using WebSocket4Net.Common; using WebSocket4Net.Protocol.FramePartReader; namespace WebSocket4Net.Protocol { - class DraftHybi10DataReader : IClientCommandReader + internal class DraftHybi10DataReader : IClientCommandReader { public DraftHybi10DataReader() { @@ -109,4 +107,4 @@ public WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offset, int le } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi10HandshakeReader.cs b/WebSocket4Net/Protocol/DraftHybi10HandshakeReader.cs index 38afc097..f8c6643e 100644 --- a/WebSocket4Net/Protocol/DraftHybi10HandshakeReader.cs +++ b/WebSocket4Net/Protocol/DraftHybi10HandshakeReader.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol +namespace WebSocket4Net.Protocol { - class DraftHybi10HandshakeReader : HandshakeReader + internal class DraftHybi10HandshakeReader : HandshakeReader { public DraftHybi10HandshakeReader(WebSocket websocket) : base(websocket) { - } public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offset, int length, out int left) @@ -22,8 +17,8 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse //If bad request, NextCommandReader will still be this HandshakeReader if (!BadRequestCode.Equals(cmdInfo.Key)) NextCommandReader = new DraftHybi10DataReader(); - + return cmdInfo; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/DraftHybi10Processor.cs b/WebSocket4Net/Protocol/DraftHybi10Processor.cs index 7b6a612d..874a112d 100644 --- a/WebSocket4Net/Protocol/DraftHybi10Processor.cs +++ b/WebSocket4Net/Protocol/DraftHybi10Processor.cs @@ -1,20 +1,17 @@ using System; using System.Collections.Generic; + #if !SILVERLIGHT -using System.Collections.Specialized; #endif -using System.IO; -using System.Linq; -using System.Text; -using SuperSocket.ClientEngine; +using System.Text; namespace WebSocket4Net.Protocol { /// /// http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 /// - class DraftHybi10Processor : ProtocolProcessorBase + internal class DraftHybi10Processor : ProtocolProcessorBase { private const string m_Magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; @@ -68,7 +65,7 @@ public override void SendHandshake(WebSocket websocket) handshakeBuilder.Append("Sec-WebSocket-Version: "); handshakeBuilder.AppendWithCrCf(VersionTag); handshakeBuilder.Append("Sec-WebSocket-Key: "); - handshakeBuilder.AppendWithCrCf(secKey); + handshakeBuilder.AppendWithCrCf(secKey); handshakeBuilder.Append(string.Format("{0}: ", m_OriginHeaderName)); handshakeBuilder.AppendWithCrCf(websocket.Origin); @@ -163,8 +160,7 @@ private byte[] EncodeDataFrame(int opCode, bool isFinal, byte[] playloadData, in } } - - if(isFinal)//Set FIN + if (isFinal)//Set FIN fragment[0] = (byte)(opCode | 0x80); else fragment[0] = (byte)opCode; @@ -231,7 +227,7 @@ public override void SendCloseHandshake(WebSocket websocket, int statusCode, str playloadData[1] = (byte)lowByte; // don't send close handshake now because the connection was closed already - if (websocket == null ||websocket.State == WebSocketState.Closed) + if (websocket == null || websocket.State == WebSocketState.Closed) return; if (!string.IsNullOrEmpty(closeReason)) @@ -337,4 +333,4 @@ private void MaskData(byte[] rawData, int offset, int length, byte[] outputData, } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/DataFramePartReader.cs b/WebSocket4Net/Protocol/FramePartReader/DataFramePartReader.cs index ddb1b613..dbced6f5 100644 --- a/WebSocket4Net/Protocol/FramePartReader/DataFramePartReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/DataFramePartReader.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - abstract class DataFramePartReader : IDataFramePartReader + internal abstract class DataFramePartReader : IDataFramePartReader { static DataFramePartReader() { @@ -29,4 +25,4 @@ public static IDataFramePartReader NewReader protected static IDataFramePartReader PayloadDataReader { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/ExtendedLenghtReader.cs b/WebSocket4Net/Protocol/FramePartReader/ExtendedLenghtReader.cs index 95ec4407..4ff094a0 100644 --- a/WebSocket4Net/Protocol/FramePartReader/ExtendedLenghtReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/ExtendedLenghtReader.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - class ExtendedLenghtReader : DataFramePartReader + internal class ExtendedLenghtReader : DataFramePartReader { public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { @@ -40,4 +36,4 @@ public override int Process(int lastLength, WebSocketDataFrame frame, out IDataF return 0; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/FixPartReader.cs b/WebSocket4Net/Protocol/FramePartReader/FixPartReader.cs index bc0bf196..73b18cdd 100644 --- a/WebSocket4Net/Protocol/FramePartReader/FixPartReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/FixPartReader.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - class FixPartReader : DataFramePartReader + internal class FixPartReader : DataFramePartReader { public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { @@ -40,4 +36,4 @@ public override int Process(int lastLength, WebSocketDataFrame frame, out IDataF return 0; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/IDataFramePartReader.cs b/WebSocket4Net/Protocol/FramePartReader/IDataFramePartReader.cs index 1a7a4ce9..c4045870 100644 --- a/WebSocket4Net/Protocol/FramePartReader/IDataFramePartReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/IDataFramePartReader.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - interface IDataFramePartReader + internal interface IDataFramePartReader { int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader); } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/MaskKeyReader.cs b/WebSocket4Net/Protocol/FramePartReader/MaskKeyReader.cs index c9b904bf..9a82bd9b 100644 --- a/WebSocket4Net/Protocol/FramePartReader/MaskKeyReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/MaskKeyReader.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - class MaskKeyReader : DataFramePartReader + internal class MaskKeyReader : DataFramePartReader { public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { @@ -32,4 +28,4 @@ public override int Process(int lastLength, WebSocketDataFrame frame, out IDataF return 0; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/FramePartReader/PayloadDataReader.cs b/WebSocket4Net/Protocol/FramePartReader/PayloadDataReader.cs index b34350b7..12f1c79e 100644 --- a/WebSocket4Net/Protocol/FramePartReader/PayloadDataReader.cs +++ b/WebSocket4Net/Protocol/FramePartReader/PayloadDataReader.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol.FramePartReader +namespace WebSocket4Net.Protocol.FramePartReader { - class PayloadDataReader : DataFramePartReader + internal class PayloadDataReader : DataFramePartReader { public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { @@ -21,4 +17,4 @@ public override int Process(int lastLength, WebSocketDataFrame frame, out IDataF return (int)((long)frame.Length - required); } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/HandshakeReader.cs b/WebSocket4Net/Protocol/HandshakeReader.cs index ba49d3e5..a599eb93 100644 --- a/WebSocket4Net/Protocol/HandshakeReader.cs +++ b/WebSocket4Net/Protocol/HandshakeReader.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Protocol { - class HandshakeReader : ReaderBase + internal class HandshakeReader : ReaderBase { private const string m_BadRequestPrefix = "HTTP/1.1 400 "; @@ -13,7 +11,6 @@ class HandshakeReader : ReaderBase static HandshakeReader() { - } public HandshakeReader(WebSocket websocket) @@ -32,42 +29,42 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse { left = 0; - // prevMatched is needed because handshake may have come - // in a number of segments, and the HeaderTerminator that - // we're looking for might lie across previous segments - // and `readBuffer`. - // - // More precisely, prevMatched > 0 if and only if the last - // byte(s) at end of the previous segment **started like** - // an incomplete HeaderTerminator that **may or may not** - // be continued and completed in current `readBuffer`. -- - // fidergo-stephane-gourichon + // prevMatched is needed because handshake may have come + // in a number of segments, and the HeaderTerminator that + // we're looking for might lie across previous segments + // and `readBuffer`. + // + // More precisely, prevMatched > 0 if and only if the last + // byte(s) at end of the previous segment **started like** + // an incomplete HeaderTerminator that **may or may not** + // be continued and completed in current `readBuffer`. -- + // fidergo-stephane-gourichon var prevMatched = m_HeadSeachState.Matched; - // At this point in code **we don't know yet** if the - // `prevMatched` bytes that match the `HeaderTerminator` - // at end of previous segment are part of a **full match** - // (in this case the value of `prevMatched` is useful) or - // just a **partial** (in that cas the value of - // `prevMatched` is irrelevant). - + // At this point in code **we don't know yet** if the + // `prevMatched` bytes that match the `HeaderTerminator` + // at end of previous segment are part of a **full match** + // (in this case the value of `prevMatched` is useful) or + // just a **partial** (in that cas the value of + // `prevMatched` is irrelevant). + var result = readBuffer.SearchMark(offset, length, m_HeadSeachState); if (result < 0) { - // We've not found the HeaderTerminator yet. We'll be - // called again when more data arrives. -- - // fidergo-stephane-gourichon + // We've not found the HeaderTerminator yet. We'll be + // called again when more data arrives. -- + // fidergo-stephane-gourichon AddArraySegment(readBuffer, offset, length); return null; } - // We've found the HeaderTerminator. All might be in - // readBuffer, or handshake might be cut across the last - // segment, or just the HeaderTerminator might be in - // readBuffer or even cut across. We must handle all - // those cases. -- fidergo-stephane-gourichon - + // We've found the HeaderTerminator. All might be in + // readBuffer, or handshake might be cut across the last + // segment, or just the HeaderTerminator might be in + // readBuffer or even cut across. We must handle all + // those cases. -- fidergo-stephane-gourichon + int findLen = result - offset; string handshake = string.Empty; @@ -75,95 +72,95 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse { if (findLen > 0) { - // In this code path we know that the handshake - // was cut across at least previous segments and - // `readBuffer`. In other words, - // `readBuffer[offset]` starts with at least one - // byte that belongs to the handshake proper - // (excluding `HeaderTerminator`). So, we add - // those bytes and extract the handshake. + // In this code path we know that the handshake + // was cut across at least previous segments and + // `readBuffer`. In other words, + // `readBuffer[offset]` starts with at least one + // byte that belongs to the handshake proper + // (excluding `HeaderTerminator`). So, we add + // those bytes and extract the handshake. this.AddArraySegment(readBuffer, offset, findLen); handshake = this.BufferSegments.Decode(Encoding.UTF8); - // Now, we need to correct `prevMatched`. Indeed, - // in this code path, any byte(s) matched at end - // of previous segment were not part of an actual - // HeaderTerminator cut across. If - // `prevMatched`>0, such byte(s) was / were a - // partial match that `readBuffer` content - // disproved. - // - // So, basically, there were actually zero bytes - // of the actual `HeaderTerminator` match in - // previous segment. We reflect that by setting - // prevMatched = 0. -- fidergo-stephane-gourichon + // Now, we need to correct `prevMatched`. Indeed, + // in this code path, any byte(s) matched at end + // of previous segment were not part of an actual + // HeaderTerminator cut across. If + // `prevMatched`>0, such byte(s) was / were a + // partial match that `readBuffer` content + // disproved. + // + // So, basically, there were actually zero bytes + // of the actual `HeaderTerminator` match in + // previous segment. We reflect that by setting + // prevMatched = 0. -- fidergo-stephane-gourichon prevMatched = 0; - // If we did not set prevMatched to zero, `left` - // would be too big and our read pointer would not - // advance enough, causing desynchronization in WS - // protocol decoding, failure to recognize further - // messages, server closing connection for lack of - // reply to ping. -- fidergo-stephane-gourichon + // If we did not set prevMatched to zero, `left` + // would be too big and our read pointer would not + // advance enough, causing desynchronization in WS + // protocol decoding, failure to recognize further + // messages, server closing connection for lack of + // reply to ping. -- fidergo-stephane-gourichon } else { - // The handshake was actually fully inside the - // previous segment. That segment possibly ended - // with `prevMatch` bytes of the - // `HeaderTerminator` that we have to shave - // off. -- fidergo-stephane-gourichon + // The handshake was actually fully inside the + // previous segment. That segment possibly ended + // with `prevMatch` bytes of the + // `HeaderTerminator` that we have to shave + // off. -- fidergo-stephane-gourichon handshake = this.BufferSegments.Decode(Encoding.UTF8, 0, this.BufferSegments.Count - prevMatched); } } else { - // In this code path, there was no previous segment. - // Everything is in `readBuffer`. + // In this code path, there was no previous segment. + // Everything is in `readBuffer`. handshake = Encoding.UTF8.GetString(readBuffer, offset, findLen); - // I'm nearly sure prevMatched is always zero already, - // if reset between invocations (see below - // `m_HeadSeachState.Matched = 0`). I'm definitely - // sure it should be zero here. An assert would be - // good. As a fallback set it. -- - // fidergo-stephane-gourichon - prevMatched = 0; + // I'm nearly sure prevMatched is always zero already, + // if reset between invocations (see below + // `m_HeadSeachState.Matched = 0`). I'm definitely + // sure it should be zero here. An assert would be + // good. As a fallback set it. -- + // fidergo-stephane-gourichon + prevMatched = 0; } - // We must tell caller how many bytes are left, with a - // formula that works in all cases. - // It works if prevMatched reflects actual match, not - // partial match, as set to zero above. -- - // fidergo-stephane-gourichon + // We must tell caller how many bytes are left, with a + // formula that works in all cases. + // It works if prevMatched reflects actual match, not + // partial match, as set to zero above. -- + // fidergo-stephane-gourichon left = length - findLen - (HeaderTerminator.Length - prevMatched); - // Rationale: left bytes are all bytes minus bytes - // consumed. We consume the part of the handshake that's - // in `readBuffer`, which is `findLen` bytes. We also - // consume the part of the `HeaderTerminator` that is in - // `readBuffer`, which is `(HeaderTerminator.Length - - // prevMatched)` bytes. + // Rationale: left bytes are all bytes minus bytes + // consumed. We consume the part of the handshake that's + // in `readBuffer`, which is `findLen` bytes. We also + // consume the part of the `HeaderTerminator` that is in + // `readBuffer`, which is `(HeaderTerminator.Length - + // prevMatched)` bytes. BufferSegments.ClearSegements(); - - // In case the object is reused, reset search state. I'm - // nearly sure this is always zero already. An assert - // would be good. As a fallback set it. -- - // fidergo-stephane-gourichon + + // In case the object is reused, reset search state. I'm + // nearly sure this is always zero already. An assert + // would be good. As a fallback set it. -- + // fidergo-stephane-gourichon m_HeadSeachState.Matched = 0; - + if (!handshake.StartsWith(m_BadRequestPrefix, StringComparison.OrdinalIgnoreCase)) { return new WebSocketCommandInfo - { - Key = OpCode.Handshake.ToString(), - Text = handshake - }; + { + Key = OpCode.Handshake.ToString(), + Text = handshake + }; } else { @@ -175,4 +172,4 @@ public override WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offse } } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/ICloseStatusCode.cs b/WebSocket4Net/Protocol/ICloseStatusCode.cs index 8512a2a9..141995bf 100644 --- a/WebSocket4Net/Protocol/ICloseStatusCode.cs +++ b/WebSocket4Net/Protocol/ICloseStatusCode.cs @@ -1,6 +1,4 @@ -using System; - -namespace WebSocket4Net.Protocol +namespace WebSocket4Net.Protocol { public interface ICloseStatusCode { @@ -16,4 +14,4 @@ public interface ICloseStatusCode short ViolatePolicy { get; } short NoStatusCode { get; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/IProtocolProcessor.cs b/WebSocket4Net/Protocol/IProtocolProcessor.cs index b5f23589..096858a8 100644 --- a/WebSocket4Net/Protocol/IProtocolProcessor.cs +++ b/WebSocket4Net/Protocol/IProtocolProcessor.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; - namespace WebSocket4Net.Protocol { public interface IProtocolProcessor @@ -32,4 +31,4 @@ public interface IProtocolProcessor WebSocketVersion Version { get; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/ProtocolProcessorBase.cs b/WebSocket4Net/Protocol/ProtocolProcessorBase.cs index d713740d..9fcd438a 100644 --- a/WebSocket4Net/Protocol/ProtocolProcessorBase.cs +++ b/WebSocket4Net/Protocol/ProtocolProcessorBase.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net.Protocol { - abstract class ProtocolProcessorBase : IProtocolProcessor + internal abstract class ProtocolProcessorBase : IProtocolProcessor { protected const string HeaderItemFormat = "{0}: {1}"; @@ -64,4 +62,4 @@ protected virtual bool ValidateVerbLine(string verbLine) return statusCode == 101; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/ProtocolProcessorFactory.cs b/WebSocket4Net/Protocol/ProtocolProcessorFactory.cs index 79f976e2..442ed0de 100644 --- a/WebSocket4Net/Protocol/ProtocolProcessorFactory.cs +++ b/WebSocket4Net/Protocol/ProtocolProcessorFactory.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; +using System.Linq; namespace WebSocket4Net.Protocol { - class ProtocolProcessorFactory + internal class ProtocolProcessorFactory { private IProtocolProcessor[] m_OrderedProcessors; @@ -21,7 +18,7 @@ public IProtocolProcessor GetProcessorByVersion(WebSocketVersion version) public IProtocolProcessor GetPreferedProcessorFromAvialable(int[] versions) { - foreach(var v in versions.OrderByDescending(i => i)) + foreach (var v in versions.OrderByDescending(i => i)) { foreach (var n in m_OrderedProcessors) { @@ -40,4 +37,4 @@ public IProtocolProcessor GetPreferedProcessorFromAvialable(int[] versions) return null; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/ReaderBase.cs b/WebSocket4Net/Protocol/ReaderBase.cs index f9e2922d..2bcc51e3 100644 --- a/WebSocket4Net/Protocol/ReaderBase.cs +++ b/WebSocket4Net/Protocol/ReaderBase.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using WebSocket4Net.Common; +using WebSocket4Net.Common; namespace WebSocket4Net.Protocol { @@ -67,4 +64,4 @@ protected void ClearBufferSegments() BufferSegments.ClearSegements(); } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/Rfc6455Processor.cs b/WebSocket4Net/Protocol/Rfc6455Processor.cs index d5df762c..4a8aaff6 100644 --- a/WebSocket4Net/Protocol/Rfc6455Processor.cs +++ b/WebSocket4Net/Protocol/Rfc6455Processor.cs @@ -1,18 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net.Protocol +namespace WebSocket4Net.Protocol { /// /// http://tools.ietf.org/html/rfc6455 /// - class Rfc6455Processor : DraftHybi10Processor + internal class Rfc6455Processor : DraftHybi10Processor { public Rfc6455Processor() : base(WebSocketVersion.Rfc6455, new CloseStatusCodeRfc6455(), "Origin") { - } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/Protocol/WebSocketDataFrame.cs b/WebSocket4Net/Protocol/WebSocketDataFrame.cs index f8e9c97a..d9d9217f 100644 --- a/WebSocket4Net/Protocol/WebSocketDataFrame.cs +++ b/WebSocket4Net/Protocol/WebSocketDataFrame.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using WebSocket4Net.Common; +using WebSocket4Net.Common; namespace WebSocket4Net.Protocol { @@ -127,4 +124,4 @@ public void Clear() m_ActualPayloadLength = -1; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/WebSocket.Net.cs b/WebSocket4Net/WebSocket.Net.cs index 3681f0e8..431302d9 100644 --- a/WebSocket4Net/WebSocket.Net.cs +++ b/WebSocket4Net/WebSocket.Net.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Net; using System.Security.Authentication; -using System.Text; -using SuperSocket.ClientEngine; namespace WebSocket4Net { @@ -12,11 +8,9 @@ public partial class WebSocket { private static List> EmptyCookies = null; - public WebSocket(string uri, string subProtocol, WebSocketVersion version) : this(uri, subProtocol, EmptyCookies, null, string.Empty, string.Empty, version) { - } public WebSocket(string uri, string subProtocol = "", List> cookies = null, List> customHeaderItems = null, string userAgent = "", string origin = "", WebSocketVersion version = WebSocketVersion.None, EndPoint httpConnectProxy = null, SslProtocols sslProtocols = SslProtocols.None, int receiveBufferSize = 0) @@ -27,4 +21,4 @@ public WebSocket(string uri, string subProtocol = "", List> cookies) public WebSocket(string uri, string subProtocol, List> cookies) : this(uri, subProtocol, cookies, WebSocketVersion.None) { - } public WebSocket(string uri, string subProtocol, WebSocketVersion version) : this(uri, subProtocol, null, version) { - } public WebSocket(string uri, string subProtocol, List> cookies, WebSocketVersion version) : this(uri, subProtocol, cookies, new List>(), null, version) { - } public WebSocket(string uri, string subProtocol, List> cookies, string userAgent, WebSocketVersion version) : this(uri, subProtocol, cookies, null, userAgent, version) { - } public WebSocket(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, WebSocketVersion version) : this(uri, subProtocol, cookies, customHeaderItems, userAgent, string.Empty, version) { - } public WebSocket(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, string origin, WebSocketVersion version) : this(uri, subProtocol, cookies, customHeaderItems, userAgent, origin, version, null) { - } public WebSocket(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, string origin, WebSocketVersion version, EndPoint httpConnectProxy) diff --git a/WebSocket4Net/WebSocket.NoSilverlight.cs b/WebSocket4Net/WebSocket.NoSilverlight.cs index afcbb8fa..81e98bc2 100644 --- a/WebSocket4Net/WebSocket.NoSilverlight.cs +++ b/WebSocket4Net/WebSocket.NoSilverlight.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Security.Authentication; -using System.Text; -using SuperSocket.ClientEngine; +using System.Security.Authentication; namespace WebSocket4Net { @@ -12,7 +7,7 @@ public partial class WebSocket #if NETCORE private SslProtocols m_SecureProtocols = SslProtocols.Tls11 | SslProtocols.Tls12; #else - private SslProtocols m_SecureProtocols = SslProtocols.Default; + private SslProtocols m_SecureProtocols = SslProtocols.Default; #endif private TcpClientSession CreateSecureTcpSession() @@ -23,4 +18,4 @@ private TcpClientSession CreateSecureTcpSession() return client; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/WebSocket.cs b/WebSocket4Net/WebSocket.cs index 83ac6575..6485c029 100644 --- a/WebSocket4Net/WebSocket.cs +++ b/WebSocket4Net/WebSocket.cs @@ -1,12 +1,7 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Net; -using System.Reflection; -using System.Text; using System.Threading; -using SuperSocket.ClientEngine; using WebSocket4Net.Common; using WebSocket4Net.Protocol; @@ -16,7 +11,6 @@ public partial class WebSocket : IDisposable { internal TcpClientSession Client { get; private set; } - private EndPoint m_RemoteEndPoint; /// @@ -66,7 +60,6 @@ public bool SupportBinary public const int DefaultReceiveBufferSize = 4096; - private int m_StateCode; internal int StateCode @@ -126,6 +119,7 @@ private Dictionary> m_CommandD #endif #if !SILVERLIGHT + /// /// set/get the local bind endpoint /// @@ -147,6 +141,7 @@ public EndPoint LocalEndPoint Client.LocalEndPoint = value; } } + #endif #if !SILVERLIGHT @@ -171,6 +166,7 @@ public SecurityOption Security return m_Security = secureClient.Security; } } + #endif private bool m_Disposed = false; @@ -204,7 +200,7 @@ private EndPoint ResolveUri(string uri, int defaultPort, out int port) return remoteEndPoint; } - TcpClientSession CreateClient(string uri) + private TcpClientSession CreateClient(string uri) { int port; var targetEndPoint = m_RemoteEndPoint = ResolveUri(uri, 80, out port); @@ -217,10 +213,9 @@ TcpClientSession CreateClient(string uri) return new AsyncTcpSession(); } - #if !NETFX_CORE - TcpClientSession CreateSecureClient(string uri) + private TcpClientSession CreateSecureClient(string uri) { int hostPos = uri.IndexOf('/', m_SecureUriPrefix.Length); @@ -262,6 +257,7 @@ TcpClientSession CreateSecureClient(string uri) return CreateSecureTcpSession(); } + #endif private void Initialize(string uri, string subProtocol, List> cookies, List> customHeaderItems, string userAgent, string origin, WebSocketVersion version, EndPoint httpConnectProxy, int receiveBufferSize) @@ -304,7 +300,7 @@ private void Initialize(string uri, string subProtocol, List 0) { frame.InnerData.DecodeMask(frame.MaskKey, offset, length); @@ -191,4 +187,4 @@ public WebSocketCommandInfo(WebSocketDataFrame frame) public short CloseStatusCode { get; private set; } } -} +} \ No newline at end of file diff --git a/WebSocket4Net/WebSocketContext.cs b/WebSocket4Net/WebSocketContext.cs index c5839914..0dcb11ab 100644 --- a/WebSocket4Net/WebSocketContext.cs +++ b/WebSocket4Net/WebSocketContext.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net +namespace WebSocket4Net { public class WebSocketContext { } -} +} \ No newline at end of file diff --git a/WebSocket4Net/WebSocketState.cs b/WebSocket4Net/WebSocketState.cs index d690806b..00863812 100644 --- a/WebSocket4Net/WebSocketState.cs +++ b/WebSocket4Net/WebSocketState.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net +namespace WebSocket4Net { public enum WebSocketState : int { @@ -13,7 +9,7 @@ public enum WebSocketState : int Closed = WebSocketStateConst.Closed } - static class WebSocketStateConst + internal static class WebSocketStateConst { public const int None = -1; @@ -25,4 +21,4 @@ static class WebSocketStateConst public const int Closed = 3; } -} +} \ No newline at end of file diff --git a/WebSocket4Net/WebSocketVersion.cs b/WebSocket4Net/WebSocketVersion.cs index 6f384286..b19fd237 100644 --- a/WebSocket4Net/WebSocketVersion.cs +++ b/WebSocket4Net/WebSocketVersion.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WebSocket4Net +namespace WebSocket4Net { public enum WebSocketVersion { @@ -11,4 +7,4 @@ public enum WebSocketVersion DraftHybi10 = 8, Rfc6455 = 13, } -} +} \ No newline at end of file