Skip to content

Commit

Permalink
feat: Added channelId to NetworkEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoTenPvP committed May 23, 2019
1 parent e69a6b3 commit 4656f8c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Ruffles/Core/NetworkEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public struct NetworkEvent
/// Useful for calculating exact receive times.
/// </summary>
/// <value>The socket receive time.</value>
public DateTime SocketReceiveTime { get; internal set; }
public DateTime SocketReceiveTime { get; internal set; }
/// <summary>
/// Gets the channelId the message was sent over.
/// </summary>
/// <value>The channelId the message was sent over.</value>
public byte ChannelId { get; internal set; }

internal HeapMemory InternalMemory;
internal bool AllowUserRecycle;
Expand Down
25 changes: 21 additions & 4 deletions Ruffles/Core/RuffleSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ public NetworkEvent Poll()
Data = new ArraySegment<byte>(),
AllowUserRecycle = false,
InternalMemory = null,
Type = NetworkEventType.Nothing
Type = NetworkEventType.Nothing,
ChannelId = 0,
SocketReceiveTime = DateTime.Now
};
}

Expand Down Expand Up @@ -830,7 +832,12 @@ internal void HandlePacket(ArraySegment<byte> payload, EndPoint endpoint)
{
Connection = connection,
Socket = this,
Type = NetworkEventType.Connect
Type = NetworkEventType.Connect,
AllowUserRecycle = false,
ChannelId = 0,
Data = new ArraySegment<byte>(),
InternalMemory = null,
SocketReceiveTime = DateTime.Now
});
}
else
Expand Down Expand Up @@ -981,7 +988,12 @@ internal void HandlePacket(ArraySegment<byte> payload, EndPoint endpoint)
{
Connection = pendingConnection,
Socket = this,
Type = NetworkEventType.Connect
Type = NetworkEventType.Connect,
AllowUserRecycle = false,
ChannelId = 0,
Data = new ArraySegment<byte>(),
InternalMemory = null,
SocketReceiveTime = DateTime.Now
});

// Send the confirmation
Expand Down Expand Up @@ -1171,7 +1183,12 @@ internal void DisconnectConnection(Connection connection, bool sendMessage, bool
{
Connection = connection,
Socket = this,
Type = timeout ? NetworkEventType.Timeout : NetworkEventType.Disconnect
Type = timeout ? NetworkEventType.Timeout : NetworkEventType.Disconnect,
AllowUserRecycle = false,
ChannelId = 0,
Data = new ArraySegment<byte>(),
InternalMemory = null,
SocketReceiveTime = DateTime.Now
});
}

Expand Down
4 changes: 3 additions & 1 deletion Ruffles/Core/SocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ public NetworkEvent PollAllSockets()
Data = new ArraySegment<byte>(),
AllowUserRecycle = false,
InternalMemory = null,
Type = NetworkEventType.Nothing
Type = NetworkEventType.Nothing,
ChannelId = 0,
SocketReceiveTime = DateTime.Now
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions Ruffles/Messaging/PacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ internal static void HandleIncomingMessage(ArraySegment<byte> payload, Connectio
AllowUserRecycle = true,
Data = new ArraySegment<byte>(memory.Buffer, (int)memory.VirtualOffset, (int)memory.VirtualCount),
InternalMemory = memory,
SocketReceiveTime = DateTime.Now
SocketReceiveTime = DateTime.Now,
ChannelId = channelId
});
}

Expand All @@ -67,7 +68,8 @@ internal static void HandleIncomingMessage(ArraySegment<byte> payload, Connectio
AllowUserRecycle = true,
Data = new ArraySegment<byte>(messageMemory.Buffer, (int)messageMemory.VirtualOffset, (int)messageMemory.VirtualCount),
InternalMemory = messageMemory,
SocketReceiveTime = DateTime.Now
SocketReceiveTime = DateTime.Now,
ChannelId = channelId
});
}
}
Expand Down

0 comments on commit 4656f8c

Please sign in to comment.