Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Refactoring with CodeMaid #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 17 additions & 34 deletions Common/ASCIIEncoding.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.Text;

namespace SuperSocket.ClientEngine
{
Expand All @@ -13,7 +12,6 @@ namespace SuperSocket.ClientEngine
/// </summary>
public class ASCIIEncoding : Encoding
{

static ASCIIEncoding()
{
m_Instance = new ASCIIEncoding();
Expand Down Expand Up @@ -80,7 +78,6 @@ public char? FallbackCharacter
/// </summary>
public byte? FallbackByte { get; private set; }


public ASCIIEncoding()
{
FallbackCharacter = '?';
Expand All @@ -92,11 +89,11 @@ public ASCIIEncoding()
/// <returns>
/// The actual number of bytes written into <paramref name="bytes"/>.
/// </returns>
/// <param name="chars">The character array containing the set of characters to encode.
/// </param><param name="charIndex">The index of the first character to encode.
/// </param><param name="charCount">The number of characters to encode.
/// <param name="chars">The character array containing the set of characters to encode.
/// </param><param name="charIndex">The index of the first character to encode.
/// </param><param name="charCount">The number of characters to encode.
/// </param><param name="bytes">The byte array to contain the resulting sequence of bytes.
/// </param><param name="byteIndex">The index at which to start writing the resulting sequence of bytes.
/// </param><param name="byteIndex">The index at which to start writing the resulting sequence of bytes.
/// </param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
Expand All @@ -105,7 +102,6 @@ public override int GetBytes(char[] chars, int charIndex, int charCount, byte[]
: GetBytesWithoutFallback(chars, charIndex, charCount, bytes, byteIndex);
}


private int GetBytesWithFallBack(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
for (int i = 0; i < charCount; i++)
Expand Down Expand Up @@ -143,19 +139,17 @@ private int GetBytesWithoutFallback(char[] chars, int charIndex, int charCount,
return charCount;
}



/// <summary>
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
/// </summary>
/// <returns>
/// The actual number of characters written into <paramref name="chars"/>.
/// </returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.
/// </param><param name="byteIndex">The index of the first byte to decode.
/// </param><param name="byteCount">The number of bytes to decode.
/// </param><param name="chars">The character array to contain the resulting set of characters.
/// </param><param name="charIndex">The index at which to start writing the resulting set of characters.
/// <param name="bytes">The byte array containing the sequence of bytes to decode.
/// </param><param name="byteIndex">The index of the first byte to decode.
/// </param><param name="byteCount">The number of bytes to decode.
/// </param><param name="chars">The character array to contain the resulting set of characters.
/// </param><param name="charIndex">The index at which to start writing the resulting set of characters.
/// </param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
Expand All @@ -164,7 +158,6 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[]
: GetCharsWithoutFallback(bytes, byteIndex, byteCount, chars, charIndex);
}


private int GetCharsWithFallback(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
for (int i = 0; i < byteCount; i++)
Expand All @@ -182,8 +175,6 @@ private int GetCharsWithFallback(byte[] bytes, int byteIndex, int byteCount, cha
return byteCount;
}



private int GetCharsWithoutFallback(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
for (int i = 0; i < byteCount; i++)
Expand All @@ -197,15 +188,12 @@ private int GetCharsWithoutFallback(byte[] bytes, int byteIndex, int byteCount,
throw new EncoderFallbackException(msg);
}


chars[charIndex + i] = byteToChar[lookupIndex];
}

return byteCount;
}



/// <summary>
/// Calculates the number of bytes produced by encoding a set of characters
/// from the specified character array.
Expand All @@ -219,29 +207,27 @@ public override int GetByteCount(char[] chars, int index, int count)
return count;
}


/// <summary>
/// Calculates the number of characters produced by decoding a sequence
/// of bytes from the specified byte array.
/// </summary>
/// <returns>
/// The number of characters produced by decoding the specified sequence of bytes. This class
/// alwas returns the value of <paramref name="count"/>.
/// alwas returns the value of <paramref name="count"/>.
/// </returns>
public override int GetCharCount(byte[] bytes, int index, int count)
{
return count;
}


/// <summary>
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
/// </summary>
/// <returns>
/// The maximum number of bytes produced by encoding the specified number of characters. This
/// class alwas returns the value of <paramref name="charCount"/>.
/// </returns>
/// <param name="charCount">The number of characters to encode.
/// <param name="charCount">The number of characters to encode.
/// </param>
public override int GetMaxByteCount(int charCount)
{
Expand All @@ -255,13 +241,12 @@ public override int GetMaxByteCount(int charCount)
/// The maximum number of characters produced by decoding the specified number of bytes. This class
/// alwas returns the value of <paramref name="byteCount"/>.
/// </returns>
/// <param name="byteCount">The number of bytes to decode.</param>
/// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount)
{
return byteCount;
}


/// <summary>
/// Gets the number of characters that are supported by this encoding.
/// This property returns a maximum value of 256, as the encoding class
Expand All @@ -272,7 +257,6 @@ public static int CharacterCount
get { return byteToChar.Length; }
}


#region Character Table

/// <summary>
Expand Down Expand Up @@ -410,11 +394,10 @@ public static int CharacterCount
(char)124 /* byte 124 */ ,
(char)125 /* byte 125 */ ,
(char)126 /* byte 126 */ ,
(char)127 /* byte 127 */
(char)127 /* byte 127 */
};

#endregion

#endregion Character Table

#region Byte Lookup Dictionary

Expand Down Expand Up @@ -553,6 +536,6 @@ public static int CharacterCount
{ (char)127, 127 }
};

#endregion
#endregion Byte Lookup Dictionary
}
}
}
12 changes: 3 additions & 9 deletions Common/ConcurrentBatchQueue.Net20.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace SuperSocket.ClientEngine
Expand All @@ -18,7 +17,7 @@ public class ConcurrentBatchQueue<T> : IBatchQueue<T>

private Func<T, bool> m_NullValidator;

class Entity
private class Entity
{
public T[] Array { get; set; }

Expand All @@ -31,7 +30,6 @@ class Entity
public ConcurrentBatchQueue()
: this(16)
{

}

/// <summary>
Expand All @@ -41,7 +39,6 @@ public ConcurrentBatchQueue()
public ConcurrentBatchQueue(int capacity)
: this(new T[capacity])
{

}

/// <summary>
Expand All @@ -52,7 +49,6 @@ public ConcurrentBatchQueue(int capacity)
public ConcurrentBatchQueue(int capacity, Func<T, bool> nullValidator)
: this(new T[capacity], nullValidator)
{

}

/// <summary>
Expand All @@ -62,7 +58,6 @@ public ConcurrentBatchQueue(int capacity, Func<T, bool> nullValidator)
public ConcurrentBatchQueue(T[] array)
: this(array, (t) => t == null)
{

}

/// <summary>
Expand Down Expand Up @@ -115,7 +110,7 @@ private bool TryEnqueue(T item, out bool full)
return false;
}

if(entity != m_Entity)
if (entity != m_Entity)
return false;

int oldCount = Interlocked.CompareExchange(ref entity.Count, count + 1, count);
Expand Down Expand Up @@ -233,7 +228,6 @@ public bool TryDequeue(IList<T> outputItems)
outputItems.Add(array[i]);
array[i] = m_Null;


if (entity.Count <= (i + 1))
break;

Expand Down Expand Up @@ -265,4 +259,4 @@ public int Count
get { return (m_Entity as Entity).Count; }
}
}
}
}
11 changes: 3 additions & 8 deletions Common/ConcurrentBatchQueue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace SuperSocket.ClientEngine
Expand All @@ -18,7 +17,7 @@ public class ConcurrentBatchQueue<T> : IBatchQueue<T>

private Func<T, bool> m_NullValidator;

class Entity
private class Entity
{
public T[] Array { get; set; }

Expand All @@ -31,7 +30,6 @@ class Entity
public ConcurrentBatchQueue()
: this(16)
{

}

/// <summary>
Expand All @@ -41,7 +39,6 @@ public ConcurrentBatchQueue()
public ConcurrentBatchQueue(int capacity)
: this(new T[capacity])
{

}

/// <summary>
Expand All @@ -52,7 +49,6 @@ public ConcurrentBatchQueue(int capacity)
public ConcurrentBatchQueue(int capacity, Func<T, bool> nullValidator)
: this(new T[capacity], nullValidator)
{

}

/// <summary>
Expand All @@ -62,7 +58,6 @@ public ConcurrentBatchQueue(int capacity, Func<T, bool> nullValidator)
public ConcurrentBatchQueue(T[] array)
: this(array, (t) => t == null)
{

}

/// <summary>
Expand Down Expand Up @@ -113,7 +108,7 @@ private bool TryEnqueue(T item, out bool full)
return false;
}

if(entity != m_Entity)
if (entity != m_Entity)
return false;

int oldCount = Interlocked.CompareExchange(ref entity.Count, count + 1, count);
Expand Down Expand Up @@ -248,4 +243,4 @@ public int Count
get { return ((Entity)m_Entity).Count; }
}
}
}
}
13 changes: 5 additions & 8 deletions Common/ConnectAsyncExtension.Net.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Text;

namespace SuperSocket.ClientEngine
{
public static partial class ConnectAsyncExtension
{
class DnsConnectState
private class DnsConnectState
{
public IPAddress[] Addresses { get; set; }

Expand Down Expand Up @@ -68,7 +65,7 @@ private static IPAddress GetNextAddress(DnsConnectState state, out Socket attemp

var currentIndex = state.NextAddressIndex;

while(attempSocket == null)
while (attempSocket == null)
{
if (currentIndex >= state.Addresses.Length)
return null;
Expand Down Expand Up @@ -138,7 +135,7 @@ private static void OnGetHostAddresses(IAsyncResult result)
{
connectState.Callback(null, connectState.State, null, e);
return;
}
}
}

var socketEventArgs = new SocketAsyncEventArgs();
Expand All @@ -152,7 +149,7 @@ private static void OnGetHostAddresses(IAsyncResult result)
SocketConnectCompleted(attempSocket, socketEventArgs);
}

static void SocketConnectCompleted(object sender, SocketAsyncEventArgs e)
private static void SocketConnectCompleted(object sender, SocketAsyncEventArgs e)
{
var connectState = e.UserToken as DnsConnectState;

Expand Down Expand Up @@ -194,4 +191,4 @@ private static void ClearSocketAsyncEventArgs(SocketAsyncEventArgs e)
e.UserToken = null;
}
}
}
}
8 changes: 2 additions & 6 deletions Common/ConnectAsyncExtension.Net35.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Text;

namespace SuperSocket.ClientEngine
{
Expand All @@ -22,4 +18,4 @@ static partial void CreateAttempSocket(DnsConnectState connectState)
connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
}
}
}
Loading