From c33d282a5c8efc15ed1007c240e2d7780cf68b7e Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Mon, 10 Mar 2025 17:35:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Frontend/RequestExtractor.cs | 8 +++---- .../NextGenerationInteractionModule.cs | 22 +++++++++---------- mROA/Implementation/RepresentationModule.cs | 2 +- mROA/mROA.csproj | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index b13a5d1..d8c9e10 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -65,7 +65,7 @@ namespace mROA.Implementation.Frontend while (true) { #if TRACE - Console.WriteLine("Waiting for request..."); + Console.WriteLine("Waiting for request..."); #endif var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; @@ -80,12 +80,12 @@ namespace mROA.Implementation.Frontend messageType: MessageType.EventRequest, token: token); Task.WaitAny(defaultRequest, cancelRequest, eventRequest); #if TRACE - Console.WriteLine("Request received"); + Console.WriteLine("Request received"); #endif if (cancelRequest.IsCompleted) { #if TRACE - Console.WriteLine("Cancelling request"); + Console.WriteLine("Cancelling request"); #endif var req = cancelRequest.Result; tokenSource.Cancel(); @@ -118,7 +118,7 @@ namespace mROA.Implementation.Frontend else { tokenSource.Cancel(); - var request = defaultRequest.Result; + var request = eventRequest.Result; _executeModule.Execute(request, _contextRepository, _representationModule); } } diff --git a/mROA/Implementation/NextGenerationInteractionModule.cs b/mROA/Implementation/NextGenerationInteractionModule.cs index 68239ea..5defb89 100644 --- a/mROA/Implementation/NextGenerationInteractionModule.cs +++ b/mROA/Implementation/NextGenerationInteractionModule.cs @@ -9,13 +9,13 @@ namespace mROA.Implementation { public class NextGenerationInteractionModule : INextGenerationInteractionModule { + private const int BufferSize = ushort.MaxValue; + private readonly Memory _buffer = new byte[BufferSize]; + private readonly List _messageBuffer = new(128); + private Task? _currentReceiving; private ISerializationToolkit? _serialization; public int ConnectionId { get; private set; } public Stream? BaseStream { get; set; } - private Task? _currentReceiving; - private const int BufferSize = ushort.MaxValue; - private readonly Memory _buffer = new byte[BufferSize]; - private readonly List _messageBuffer = new (128); public void Inject(T dependency) @@ -36,7 +36,6 @@ namespace mROA.Implementation if (_currentReceiving != null) return _currentReceiving; _currentReceiving = Task.Run(async () => await GetNextMessage()); return _currentReceiving; - } public async Task PostMessage(NetworkMessage message) @@ -46,7 +45,7 @@ namespace mROA.Implementation if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); - + // Console.WriteLine("Sending {0}", JsonSerializer.Serialize(message)); @@ -62,6 +61,7 @@ namespace mROA.Implementation } public NetworkMessage[] UnhandledMessages => _messageBuffer.ToArray(); + public NetworkMessage? FirstByFilter(Predicate predicate) { return _messageBuffer.FirstOrDefault(m => predicate(m)); @@ -79,23 +79,23 @@ namespace mROA.Implementation // Console.WriteLine("Receiving message"); var firstBit = (byte)BaseStream.ReadByte(); var secondBit = (byte)BaseStream.ReadByte(); - - var len = BitConverter.ToUInt16(new[] { firstBit, secondBit}); + + var len = BitConverter.ToUInt16(new[] { firstBit, secondBit }); var localSpan = _buffer.Slice(0, len); - + await BaseStream.ReadExactlyAsync(localSpan); // Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len])); var message = _serialization.Deserialize(localSpan.Span); #if TRACE - Console.WriteLine($"Received Message {message.SchemaId} - {message.Id}"); + Console.WriteLine($"Received Message {message.Id} - {message.SchemaId}"); TransmissionConfig.TotalTransmittedBytes += len; Console.WriteLine($"Total recieced bytes are {TransmissionConfig.TotalTransmittedBytes}"); #endif _messageBuffer.Add(message); _currentReceiving = Task.Run(async () => await GetNextMessage()); - + return message; } } diff --git a/mROA/Implementation/RepresentationModule.cs b/mROA/Implementation/RepresentationModule.cs index c04f160..58f2ce5 100644 --- a/mROA/Implementation/RepresentationModule.cs +++ b/mROA/Implementation/RepresentationModule.cs @@ -91,7 +91,7 @@ namespace mROA.Implementation if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); #if TRACE - Console.WriteLine($"Posting message: {id} - {messageType}"); + Console.WriteLine($"Posting message: {id} - {messageType} to {Id}"); #endif var serialized = _serialization.Serialize(payload, payloadType); diff --git a/mROA/mROA.csproj b/mROA/mROA.csproj index e9d980c..8723457 100644 --- a/mROA/mROA.csproj +++ b/mROA/mROA.csproj @@ -21,7 +21,7 @@ - + TRACE;