Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pption to force reliable ordering of TCP messages. #15

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,6 @@ GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
*.ide

# Visual Studio directories
.vs/
1 change: 1 addition & 0 deletions Hazel/Hazel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="ObjectPool.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SendOption.cs" />
<Compile Include="Tcp\TcpOptions.cs" />
<Compile Include="Udp\SendOptionInternal.cs" />
<Compile Include="Tcp\StateObject.cs" />
<Compile Include="ConnectionStatistics.cs" />
Expand Down
13 changes: 11 additions & 2 deletions Hazel/Tcp/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ void BodyReadCallback(byte[] bytes)
//Begin receiving from the start
try
{
//Fire DataReceived event before reading next message.
if(TcpOptions.ForceReliableOrdering == true)
{
InvokeDataReceived(bytes, SendOption.FragmentedReliable);
}

StartWaitingForHeader(BodyReadCallback);
}
catch (Exception e)
Expand All @@ -199,8 +205,11 @@ void BodyReadCallback(byte[] bytes)

Statistics.LogFragmentedReceive(bytes.Length, bytes.Length + 4);

//Fire DataReceived event
InvokeDataReceived(bytes, SendOption.FragmentedReliable);
//Fire DataReceived event after reading next message for better throughput.
if(TcpOptions.ForceReliableOrdering == false)
{
InvokeDataReceived(bytes, SendOption.FragmentedReliable);
}
}

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions Hazel/Tcp/TcpOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hazel.Tcp
{
public static class TcpOptions
{
/// <summary>
/// Force data received even to fire before reading the next message.
/// Setting to false may offer a slight performance advantage at the risk of compromising message ordering.
/// </summary>
public static bool ForceReliableOrdering { get; set; } = false;
}
}