/// A compounding multiplier to back off resend timeout.
/// Applied to ping before first timeout when ResendTimeout == 0.
/// </summary>
- public volatile float ResendPingMultiplier = 3;
+ public volatile float ResendPingMultiplier = 2;
/// <summary>
/// Holds the last ID allocated.
/// This returns the average ping for a one-way trip as calculated from the reliable packets that have been sent
/// and acknowledged by the endpoint.
/// </remarks>
- public float AveragePingMs = 500;
+ public float AveragePingMs = 200;
/// <summary>
/// The maximum times a message should be resent before marking the endpoint as disconnected.
return 0;
}
- this.NextTimeout = (int)Math.Min(this.NextTimeout * connection.ResendPingMultiplier, connection.DisconnectTimeout);
+ this.NextTimeout = (int)Math.Min(this.NextTimeout * connection.ResendPingMultiplier, 1500);
try
{
connection.WriteBytesToConnection(this.Data, this.Length);
this,
buffer,
sendLength,
- ResendTimeout > 0 ? ResendTimeout : (int)Math.Max(300, Math.Min(AveragePingMs * this.ResendPingMultiplier, 2000)),
+ ResendTimeout > 0 ? ResendTimeout : ClampToInt(AveragePingMs * this.ResendPingMultiplier, 300, 1000),
ackCallback);
if (!reliableDataPacketsSent.TryAdd(id, packet))
}
}
+ public static int ClampToInt(float value, int min, int max)
+ {
+ if (value < min) return min;
+ if (value > max) return max;
+ return (int)value;
+ }
+
/// <summary>
/// Sends the bytes reliably and stores the send.
/// </summary>
this.socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
}
- socket.ReceiveBufferSize = 4194304;
- socket.SendBufferSize = 1048576;
+ socket.ReceiveBufferSize = BufferSize;
+ socket.SendBufferSize = BufferSize;
reliablePacketTimer = new Timer(ManageReliablePackets, null, 100, Timeout.Infinite);
}
if (this.socket != null)
{
- try
- {
- this.socket.Shutdown(SocketShutdown.Both);
- }
- catch { }
- this.socket.Close();
- this.socket.Dispose();
+ try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+ try { this.socket.Close(); } catch { }
+ try { this.socket.Dispose(); } catch { }
this.socket = null;
}