Skip to content

Commit

Permalink
Test to see if volatile is not sufficient for tracking pingAcks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Schulz committed Jun 12, 2024
1 parent dc8a5db commit 0b8d1bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Hazel/Udp/UdpConnection.KeepAlive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int KeepAliveInterval
private int keepAliveInterval = 1500;

public int MissingPingsUntilDisconnect { get; set; } = 6;
private volatile int pingsSinceAck = 0;
private int pingsSinceAck = 0;

/// <summary>
/// The timer creating keepalive pulses.
Expand Down Expand Up @@ -94,7 +94,7 @@ private void HandleKeepAlive(object state)

try
{
this.pingsSinceAck++;
Interlocked.Increment(ref this.pingsSinceAck);
SendPing();
}
catch
Expand Down
2 changes: 1 addition & 1 deletion Hazel/Udp/UdpConnection.Reliable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private bool ProcessReliableReceive(byte[] bytes, int offset, out ushort id)
/// <param name="bytes">The buffer containing the data.</param>
private void AcknowledgementMessageReceive(byte[] bytes, int bytesReceived)
{
this.pingsSinceAck = 0;
Interlocked.Exchange(ref this.pingsSinceAck, 0);

ushort id = (ushort)((bytes[1] << 8) + bytes[2]);
AcknowledgeMessageId(id);
Expand Down
1 change: 1 addition & 0 deletions Hazel/Udp/UdpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract partial class UdpConnection : NetworkConnection

public UdpConnection(ILogger logger) : base()
{
logger.WriteInfo("Experimental version: Interlocked.Increment on pingsSinceAck");
this.bufferPool = new ObjectPool<SmartBuffer>(() => new SmartBuffer(this.bufferPool, 1024));

this.logger = logger;
Expand Down

0 comments on commit 0b8d1bc

Please sign in to comment.