From d2c2f8d65791615832e017ab98b54178265ddf9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 16 Apr 2020 22:20:42 +0200 Subject: [PATCH] test & fix --- Capnp.Net.Runtime.Tests/Dtbdct.cs | 6 +++ Capnp.Net.Runtime.Tests/Interception.cs | 38 +++++++++++++++++++ Capnp.Net.Runtime.Tests/LocalRpc.cs | 6 +++ Capnp.Net.Runtime.Tests/Testsuite.cs | 18 +++++++++ Capnp.Net.Runtime/FramePump.cs | 8 +++- .../Rpc/Interception/CallContext.cs | 4 +- 6 files changed, 76 insertions(+), 4 deletions(-) diff --git a/Capnp.Net.Runtime.Tests/Dtbdct.cs b/Capnp.Net.Runtime.Tests/Dtbdct.cs index d67860d..4a4c9c6 100644 --- a/Capnp.Net.Runtime.Tests/Dtbdct.cs +++ b/Capnp.Net.Runtime.Tests/Dtbdct.cs @@ -188,5 +188,11 @@ namespace Capnp.Net.Runtime.Tests { NewDtbdctTestbed().RunTest(Testsuite.CallAfterFinish2); } + + [TestMethod] + public void LegacyAccess() + { + NewDtbdctTestbed().RunTest(Testsuite.LegacyAccess); + } } } diff --git a/Capnp.Net.Runtime.Tests/Interception.cs b/Capnp.Net.Runtime.Tests/Interception.cs index 4d86f85..c1c7e50 100644 --- a/Capnp.Net.Runtime.Tests/Interception.cs +++ b/Capnp.Net.Runtime.Tests/Interception.cs @@ -395,6 +395,44 @@ namespace Capnp.Net.Runtime.Tests } } + [TestMethod] + public void InterceptClientSideModifyPipelinedCall() + { + var policy = new MyPolicy("a"); + + (var server, var client) = SetupClientServerPair(); + + using (server) + using (client) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + server.Main = impl; + using (var main = policy.Attach(client.GetMain())) + { + var req = main.GetNull().Eager().GetCallSequence(0); + Assert.IsTrue(policy.Calls.TryReceive(out var ccGetNull)); + Assert.IsTrue(policy.Calls.TryReceive(out var ccGetCallSequence)); + + ccGetNull.ForwardToBob(); + + Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout)); + + ccGetNull.ReturnToAlice(); + + ccGetCallSequence.Bob = Proxy.Share(impl); + ccGetCallSequence.ForwardToBob(); + + Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout)); + + ccGetCallSequence.ReturnToAlice(); + + Assert.IsTrue(req.IsCompleted && !req.IsFaulted && !req.IsCanceled); + Assert.AreEqual(0u, req.Result); + } + } + } + [TestMethod] public void InterfaceAndMethodId() { diff --git a/Capnp.Net.Runtime.Tests/LocalRpc.cs b/Capnp.Net.Runtime.Tests/LocalRpc.cs index a618b84..36ab7e5 100644 --- a/Capnp.Net.Runtime.Tests/LocalRpc.cs +++ b/Capnp.Net.Runtime.Tests/LocalRpc.cs @@ -140,6 +140,12 @@ namespace Capnp.Net.Runtime.Tests NewLocalTestbed().RunTest(Testsuite.Ownership3); } + [TestMethod] + public void LegacyAccess() + { + NewLocalTestbed().RunTest(Testsuite.LegacyAccess); + } + [TestMethod] public void EagerRace() { diff --git a/Capnp.Net.Runtime.Tests/Testsuite.cs b/Capnp.Net.Runtime.Tests/Testsuite.cs index c912b11..29dbfd1 100644 --- a/Capnp.Net.Runtime.Tests/Testsuite.cs +++ b/Capnp.Net.Runtime.Tests/Testsuite.cs @@ -855,5 +855,23 @@ namespace Capnp.Net.Runtime.Tests } } } + + public static void LegacyAccess(ITestbed testbed) + { + var impl = new TestMoreStuffImpl(new Counters()); + using (var main = testbed.ConnectMain(impl)) + { + var task = main.Echo(new TestCallOrderImpl()); + var answer = Impatient.TryGetAnswer(task); + Assert.IsNotNull(answer); + var cap = answer.Access(new MemberAccessPath(0)); + using (var proxy = (ITestCallOrder)CapabilityReflection.CreateProxy(cap)) + { + var seq = proxy.GetCallSequence(0); + testbed.MustComplete(seq); + Assert.AreEqual(0u, seq.Result); + } + } + } } } diff --git a/Capnp.Net.Runtime/FramePump.cs b/Capnp.Net.Runtime/FramePump.cs index e2ecabc..dad87c3 100644 --- a/Capnp.Net.Runtime/FramePump.cs +++ b/Capnp.Net.Runtime/FramePump.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -160,9 +161,12 @@ namespace Capnp } } } - catch (EndOfStreamException) + catch (Exception exception) when (exception is EndOfStreamException || + exception is IOException ioex && + ioex.InnerException is SocketException sockex && + sockex.SocketErrorCode == SocketError.Interrupted) { - Logger.LogWarning("Encountered End of Stream"); + Logger.LogInformation("Encountered end of stream"); } catch (InvalidDataException e) { diff --git a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs index 3911fae..1caf2b6 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs @@ -27,13 +27,13 @@ namespace Capnp.Rpc.Interception public ConsumedCapability Access(MemberAccessPath access) { - return new LocalAnswerCapability(_futureResult.Task, access); + return _callContext._censorCapability.Policy.Attach(new LocalAnswerCapability(_futureResult.Task, access)); } public ConsumedCapability Access(MemberAccessPath _, Task task) { var proxyTask = task.AsProxyTask(); - return new LocalAnswerCapability(proxyTask); + return _callContext._censorCapability.Policy.Attach(new LocalAnswerCapability(proxyTask)); } public void Dispose()