From 52fa0ffb5ef8e9496bc2806a15edf02b0fa36d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 25 Aug 2019 22:53:15 +0200 Subject: [PATCH] Use consecutive question IDs rather than random numbers --- Capnp.Net.Runtime/Rpc/RpcEngine.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Capnp.Net.Runtime/Rpc/RpcEngine.cs b/Capnp.Net.Runtime/Rpc/RpcEngine.cs index f114197..c88d0f4 100644 --- a/Capnp.Net.Runtime/Rpc/RpcEngine.cs +++ b/Capnp.Net.Runtime/Rpc/RpcEngine.cs @@ -74,7 +74,6 @@ namespace Capnp.Rpc readonly RpcEngine _host; readonly IEndpoint _tx; - readonly Random _random = new Random(); readonly Dictionary>> _importTable = new Dictionary>>(); readonly Dictionary> _exportTable = new Dictionary>(); readonly Dictionary _revExportTable = new Dictionary(); @@ -85,6 +84,7 @@ namespace Capnp.Rpc long _recvCount; long _sendCount; + uint _nextId; internal RpcEndpoint(RpcEngine host, IEndpoint tx) { @@ -185,9 +185,9 @@ namespace Capnp.Rpc ReleaseExport(preliminaryId, 1); } - uint RandId() + uint NextId() { - return unchecked((uint)_random.Next(int.MinValue, int.MaxValue)); + return _nextId++; } uint AllocateExport(Skeleton providedCapability, out bool first) @@ -213,7 +213,7 @@ namespace Capnp.Rpc { do { - id = RandId(); + id = NextId(); } while (_exportTable.ContainsKey(id)); @@ -236,12 +236,12 @@ namespace Capnp.Rpc { lock (_reentrancyBlocker) { - uint questionId = RandId(); + uint questionId = NextId(); var question = new PendingQuestion(this, questionId, target, inParams); while (!_questionTable.ReplacementTryAdd(questionId, question)) { - questionId = RandId(); + questionId = NextId(); var oldQuestion = question; question = new PendingQuestion(this, questionId, target, inParams); oldQuestion.Dispose(); @@ -277,11 +277,11 @@ namespace Capnp.Rpc lock (_reentrancyBlocker) { - uint id = RandId(); + uint id = NextId(); while (!_pendingDisembargos.ReplacementTryAdd(id, tcs)) { - id = RandId(); + id = NextId(); } return (tcs, id);