From fba68522c02b862e0bf92981362514d5ec1bcafd Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 5 Nov 2024 23:23:52 +0100 Subject: [PATCH] Fix C# connection to correctly mark message as sent --- csharp/src/Ice/ConnectionI.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs index 13c0172bdcf..bdb68e101da 100644 --- a/csharp/src/Ice/ConnectionI.cs +++ b/csharp/src/Ice/ConnectionI.cs @@ -607,15 +607,23 @@ public override bool startAsync(int operation, Ice.Internal.AsyncCallback comple observerStartWrite(_writeStream.getBuffer()); } - bool completed; - if (_transceiver.startWrite(_writeStream.getBuffer(), completedCallback, this, out completed)) + bool messageWritten = false; + bool completedSynchronously = + _transceiver.startWrite( + _writeStream.getBuffer(), + completedCallback, + this, + out messageWritten); + // If the startWrite call consumed the complete buffer, we assume the message is sent now for + // at-most-once semantics. + if (messageWritten && _sendStreams.Count > 0) { - // If the write completed immediately and the buffer - if (completed && _sendStreams.Count > 0) - { - // The whole message is written, assume it's sent now for at-most-once semantics. - _sendStreams.First.Value.isSent = true; - } + _sendStreams.First.Value.isSent = true; + } + + if (completedSynchronously) + { + // If the write completed synchronously, we need to call the completedCallback. completedCallback(this); } }