Second Unity code equating session

This commit is contained in:
2025-05-06 23:25:52 +03:00
parent dae96c9674
commit 2155c8f0d8
5 changed files with 11 additions and 59 deletions
@@ -30,18 +30,12 @@ namespace mROA.Implementation.Backend
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
IRepresentationModule representationModule, IEndPointContext endPointContext)
{
#if TRACE
Console.WriteLine(command.GetType().Name);
#endif
try
{
ThrowIfNotInjected(contextRepository);
if (command is CancelRequest)
{
#if TRACE
Console.WriteLine("Final cancelling request");
#endif
return CancelExecution(command);
}
@@ -76,9 +70,6 @@ namespace mROA.Implementation.Backend
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
if (command.CommandId == -1)
{
#if TRACE
Console.WriteLine("Disposing object");
#endif
contextRepository.ClearObject(command.ObjectId, endPointContext);
}
@@ -189,9 +180,7 @@ namespace mROA.Implementation.Backend
var tokenSource = new CancellationTokenSource();
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
var token = tokenSource.Token;
#if TRACE
token.Register(() => Console.WriteLine($"Cancellation requested check {command.Id}"));
#endif
try
{
invoker.Invoke(instance, parameters, new object[] { executionContext, token }, _ =>
@@ -33,15 +33,6 @@ namespace mROA.Implementation.Backend
Console.WriteLine("Enter Backspace to stop");
Task.Run(HandleIncomingConnections);
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Backspace)
break;
}
Console.WriteLine("Stopping");
}
public void Dispose()
@@ -62,13 +53,13 @@ namespace mROA.Implementation.Backend
}
}
private void HandleIncomingConnections()
private async Task HandleIncomingConnections()
{
ThrowIfNotInjected();
while (true)
{
var client = _tcpListener.AcceptTcpClient();
var client = await _tcpListener.AcceptTcpClientAsync();
Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}");
var interaction = Activator.CreateInstance(_interactionModuleType!) as IChannelInteractionModule;
@@ -84,10 +75,12 @@ namespace mROA.Implementation.Backend
var streamExtractor =
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context);
interaction.IsConnected = () => streamExtractor.IsConnected;
streamExtractor.MessageReceived = message => { interaction.ReceiveChanel.Writer.WriteAsync(message); };
streamExtractor.SingleReceive();
var connectionRequest = interaction.GetNextMessageReceiving(false)
.GetAwaiter().GetResult()!;
streamExtractor.MessageReceived = async message =>
{
await interaction.ReceiveChanel.Writer.WriteAsync(message);
};
Task.Run(() => streamExtractor.SingleReceive());
var connectionRequest = await interaction.ReceiveChanel.Reader.ReadAsync();
var cts = new CancellationTokenSource();
switch (connectionRequest.MessageType)
@@ -121,7 +114,6 @@ namespace mROA.Implementation.Backend
recoveryInteraction.Restart(false);
Console.WriteLine("Connection recovery for client {0} finished", recoveryRequest.Id);
break;
}
default:
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using mROA.Abstract;
using Exception = System.Exception;
@@ -1,7 +1,4 @@
using System;
#if TRACE
using System.Diagnostics;
#endif
using System.Threading;
using System.Threading.Tasks;
using mROA.Abstract;
@@ -16,8 +13,6 @@ namespace mROA.Implementation.Frontend
private IMethodRepository? _methodRepository;
// private IContextRepository? _realContextRepository;
// private IContextRepository? _remoteContextRepository;
private IRepresentationModule? _representationModule;
private IContextualSerializationToolKit? _serializationToolkit;
private IEndPointContext _context;
@@ -51,9 +46,6 @@ namespace mROA.Implementation.Frontend
try
{
#if TRACE
var sw = new Stopwatch();
#endif
var streamTokenSource = new CancellationTokenSource();
@@ -69,20 +61,6 @@ namespace mROA.Implementation.Frontend
await foreach (var command in query)
{
#if TRACE
Console.WriteLine("Waiting for request...");
if (sw.IsRunning)
{
sw.Stop();
Console.WriteLine(
$"Request handling took {Math.Round(sw.Elapsed.TotalMilliseconds * 1000.0)} microseconds.");
}
#endif
#if TRACE
Console.WriteLine("Request received");
sw.Restart();
#endif
switch (command.originalType)
{
case EMessageType.CallRequest:
@@ -60,13 +60,9 @@ namespace mROA.Implementation.Frontend
continue;
var serialized = _serializationToolkit.Serialize(post, _context);
#if TRACE
Console.WriteLine("Untrusted write start");
#endif
await udpClient.SendAsync(serialized, serialized.Length);
#if TRACE
Console.WriteLine("Untrusted write finished");
#endif
}
}