public void TestRpcLocalAsyncSingleCall() { Console.WriteLine("LocalAsyncSingleCall"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Console.WriteLine("Calling RPC"); Console.WriteLine("Waiting for RPC Result"); CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.CallRpcWithResultAsync("func1", source.Token, RemoteProcedureCall.PackRpcValues(Value.MakeDouble(2.0))); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var call1Result = RemoteProcedureCall.UnpackRpcValues(task.Result, NtType.Double); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcSpeedAsyncSingleCall() { Console.WriteLine("SpeedAsyncSingleCall"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; ++i) { CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.CallRpcWithResultAsync("func1", source.Token, RemoteProcedureCall.PackRpcValues(Value.MakeDouble(i))); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var res = RemoteProcedureCall.UnpackRpcValues(task.Result, NtType.Double); Assert.AreNotEqual(0, res.Count, "RPC Result empty"); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
/// <inheritdoc cref="RemoteProcedureCall.UnpackRpcValues(byte[], List{NtType})"/> public List <Value> UnpackRpcValues(byte[] packed, List <NtType> types) { return(RemoteProcedureCall.UnpackRpcValues(packed, types)); }
/// <inheritdoc cref="RemoteProcedureCall.PackRpcValues(List{Value})"/> public byte[] PackRpcValues(List <Value> values) { return(RemoteProcedureCall.PackRpcValues(values)); }
/// <inheritdoc cref="RemoteProcedureCall.PackRpcValues(Value[])"/> public byte[] PackRpcValues(params Value[] values) { return(RemoteProcedureCall.PackRpcValues(values)); }
/// <inheritdoc cref="RemoteProcedureCall.UnpackRpcDefinition(byte[], ref RpcDefinition)"/> public bool UnpackRpcDefinition(byte[] packed, ref RpcDefinition def) { return(RemoteProcedureCall.UnpackRpcDefinition(packed, ref def)); }
/// <inheritdoc cref="RemoteProcedureCall.PackRpcDefinition(RpcDefinition)"/> public byte[] PackRpcDefinition(RpcDefinition def) { return(RemoteProcedureCall.PackRpcDefinition(def)); }