Skip to content

Commit

Permalink
running code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Sep 23, 2024
1 parent 837b6e8 commit ac069f9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions source/Runtime/Client/StandAlone/ClientSslHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace JamesFrowen.SimpleWeb
{
internal class ClientSslHelper
class ClientSslHelper
{
private readonly bool allowErrors;
readonly bool allowErrors;

public ClientSslHelper(bool allowErrors)
{
Expand Down Expand Up @@ -38,7 +38,7 @@ internal bool TryCreateStream(Connection conn, Uri uri)

Stream CreateStream(NetworkStream stream, Uri uri)
{
var sslStream = new SslStream(stream, true, ValidateServerCertificate);
SslStream sslStream = new SslStream(stream, true, ValidateServerCertificate);
sslStream.AuthenticateAsClient(uri.Host);
return sslStream;
}
Expand All @@ -56,7 +56,7 @@ bool ValidateServerCertificate(object sender, X509Certificate certificate, X509C
}

// Do not allow this client to communicate with unauthenticated servers.
return false;
return false;
}
}
}
10 changes: 5 additions & 5 deletions source/Runtime/Client/StandAlone/WebSocketClientStandAlone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public override void Connect(Uri serverAddress)
state = ClientState.Connecting;

// create connection here before thread so that send queue exist before connected
var client = new TcpClient();
TcpClient client = new TcpClient();
tcpConfig.ApplyTo(client);

// create connection object here so dispose correctly disconnects on failed connect
conn = new Connection(client, AfterConnectionDisposed);

var receiveThread = new Thread(() => ConnectAndReceiveLoop(serverAddress));
Thread receiveThread = new Thread(() => ConnectAndReceiveLoop(serverAddress));
receiveThread.IsBackground = true;
receiveThread.Start();
}
Expand Down Expand Up @@ -79,9 +79,9 @@ void ConnectAndReceiveLoop(Uri serverAddress)

receiveQueue.Enqueue(new Message(EventType.Connected));

var sendThread = new Thread(() =>
Thread sendThread = new Thread(() =>
{
var sendConfig = new SendLoop.Config(
SendLoop.Config sendConfig = new SendLoop.Config(
conn,
bufferSize: Constants.HeaderSize + Constants.MaskSize + maxMessageSize,
setMask: true);
Expand All @@ -93,7 +93,7 @@ void ConnectAndReceiveLoop(Uri serverAddress)
sendThread.IsBackground = true;
sendThread.Start();

var config = new ReceiveLoop.Config(conn,
ReceiveLoop.Config config = new ReceiveLoop.Config(conn,
maxMessageSize,
false,
receiveQueue,
Expand Down
2 changes: 1 addition & 1 deletion source/Runtime/Client/Webgl/SimpleWebJSLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace JamesFrowen.SimpleWeb
{
internal static class SimpleWebJSLib
static class SimpleWebJSLib
{
#if UNITY_WEBGL
[DllImport("__Internal")]
Expand Down
18 changes: 9 additions & 9 deletions source/Runtime/Common/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static void ToggleMask(byte[] src, int srcOffset, byte[] dst, int dstOffs
{
for (int i = 0; i < messageLength; i++)
{
byte maskByte = maskBuffer[maskOffset + i % Constants.MaskSize];
byte maskByte = maskBuffer[maskOffset + (i % Constants.MaskSize)];
dst[dstOffset + i] = (byte)(src[srcOffset + i] ^ maskByte);
}
}
Expand All @@ -104,14 +104,14 @@ static int GetMessageLength(byte[] buffer, int offset, byte lenByte)
{
// header is 8 bytes
ulong value = 0;
value |= ((ulong)buffer[offset + 2] << 56);
value |= ((ulong)buffer[offset + 3] << 48);
value |= ((ulong)buffer[offset + 4] << 40);
value |= ((ulong)buffer[offset + 5] << 32);
value |= ((ulong)buffer[offset + 6] << 24);
value |= ((ulong)buffer[offset + 7] << 16);
value |= ((ulong)buffer[offset + 8] << 8);
value |= ((ulong)buffer[offset + 9] << 0);
value |= (ulong)buffer[offset + 2] << 56;
value |= (ulong)buffer[offset + 3] << 48;
value |= (ulong)buffer[offset + 4] << 40;
value |= (ulong)buffer[offset + 5] << 32;
value |= (ulong)buffer[offset + 6] << 24;
value |= (ulong)buffer[offset + 7] << 16;
value |= (ulong)buffer[offset + 8] << 8;
value |= (ulong)buffer[offset + 9] << 0;

if (value > int.MaxValue)
{
Expand Down
8 changes: 4 additions & 4 deletions source/Runtime/Common/ReceiveLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JamesFrowen.SimpleWeb
{
internal static class ReceiveLoop
static class ReceiveLoop
{
public struct Config
{
Expand Down Expand Up @@ -135,7 +135,7 @@ static void ReadOneMessage(Config config, byte[] buffer)
else
{
// todo cache this to avoid allocations
var fragments = new Queue<ArrayBuffer>();
Queue<ArrayBuffer> fragments = new Queue<ArrayBuffer>();
fragments.Enqueue(CopyMessageToBuffer(bufferPool, expectMask, buffer, msgOffset, header.payloadLength));
int totalSize = header.payloadLength;

Expand Down Expand Up @@ -175,7 +175,7 @@ static Header ReadHeader(Config config, byte[] buffer, bool opCodeContinuation =
{
(Connection conn, int maxMessageSize, bool expectMask, ConcurrentQueue<Message> queue, BufferPool bufferPool) = config;
Stream stream = conn.stream;
var header = new Header();
Header header = new Header();

// read 2
header.offset = ReadHelper.Read(stream, buffer, header.offset, Constants.HeaderMinSize);
Expand Down Expand Up @@ -264,7 +264,7 @@ static string GetCloseMessage(byte[] buffer, int msgOffset, int payloadLength)

static int GetCloseCode(byte[] buffer, int msgOffset)
{
return buffer[msgOffset + 0] << 8 | buffer[msgOffset + 1];
return (buffer[msgOffset + 0] << 8) | buffer[msgOffset + 1];
}
}
}

0 comments on commit ac069f9

Please sign in to comment.