Skip to content

Commit

Permalink
Update RUDP.Connection.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Jul 3, 2024
1 parent f176661 commit b82dbae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/rudp/partials/utils/RUDP.Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading.Tasks;
using Byter;

namespace Netly
{
Expand All @@ -24,7 +25,7 @@ internal sealed class Connection
public Action<byte[], MessageType> OnData;
public Action<string, byte[], MessageType> OnEvent;
private readonly object _sendIdLocker, _databaseLocker;
private const byte PingByte = 0, SynByte = 16, AckByte = 32, SynAck = 64, Fin = 128;
private const byte PingByte = 0, SynByte = 16, AckByte = 32, SynAckByte = 64, FinByte = 128;

private class Package
{
Expand All @@ -35,20 +36,24 @@ private class Package

private Connection()
{
var logger = NetlyEnvironment.Logger;
string @class = nameof(Connection);

_isServer = false;
_database = new Dictionary<uint, bool>();
_receivedQueue = new Dictionary<uint, byte[]>();
_receivedId = 0;
_sendId = 0;
_framing = new NetlyEnvironment.MessageFraming();
_isOpeningOrClosing = false;
OnOpen = () => { };
OnClose = () => { };
OnOpenFail = (_) => { };
OnData = (_, __) => { };
OnEvent = (_, __, ___) => { };
_sendIdLocker = new object();
_databaseLocker = new object();

OnOpen = () => logger.Create($"{@class} -> {nameof(OnOpen)}");
OnClose = () => logger.Create($"{@class} -> {nameof(OnClose)}");
OnOpenFail = e => logger.Create($"{@class} -> {nameof(OnOpenFail)}: {e}");
OnData = (d, t) => logger.Create($"{@class} -> {nameof(OnData)}: {d.GetString()} ({t})");
OnEvent = (n, d, t) => logger.Create($"{@class} -> {nameof(OnData)} ({n}): {d.GetString()} ({t})");
}

public Connection(Host host, Socket socket, bool isServer) : this()
Expand Down

0 comments on commit b82dbae

Please sign in to comment.