Skip to content

Commit

Permalink
Improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Nov 2, 2022
1 parent 28b0dac commit 89b7240
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.0.3 - 2022-11-02

Improve logging.

## v1.0.2 - 2022-11-02

Improve logging.
Expand Down
18 changes: 12 additions & 6 deletions src/remoting/dotnet-remoting/Remoting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class RemoteCommunicator
private NetworkStream _tcpCommSocketStream = default!;
private NetworkStream _tcpDataSocketStream = default!;
private IDataSource _dataSource;
private ILogger _logger = default!;

/// <summary>
/// Initializes a new instance of the RemoteCommunicator.
Expand Down Expand Up @@ -108,7 +109,7 @@ JsonElement Read(byte[] jsonRequest)

// get request message
var size = ReadSize(_tcpCommSocketStream);
var jsonRequest = _tcpCommSocketStream.ReadExactly(size);
var jsonRequest = _tcpCommSocketStream.ReadExactly(size, _logger);
var request = Read(jsonRequest);

// process message
Expand Down Expand Up @@ -223,7 +224,7 @@ JsonElement Read(byte[] jsonRequest)
if (rawContext.TryGetProperty("requestConfiguration", out var requestConfigurationElement))
requestConfiguration = JsonSerializer.Deserialize<IReadOnlyDictionary<string, JsonElement>?>(requestConfigurationElement);

var logger = new Logger(_tcpCommSocketStream);
_logger = new Logger(_tcpCommSocketStream);

var context = new DataSourceContext(
resourceLocator,
Expand All @@ -232,7 +233,7 @@ JsonElement Read(byte[] jsonRequest)
requestConfiguration
);

await _dataSource.SetContextAsync(context, logger, CancellationToken.None);
await _dataSource.SetContextAsync(context, _logger, CancellationToken.None);
}

else if (methodName == "getCatalogRegistrations")
Expand Down Expand Up @@ -349,14 +350,16 @@ private async Task<ReadOnlyMemory<double>> HandleReadDataAsync(
await Utilities.SendToServerAsync(readDataRequest, _tcpCommSocketStream);

var size = ReadSize(_tcpDataSocketStream);
var data = _tcpDataSocketStream.ReadExactly(size);
_logger.LogTrace("Try to read {ByteCount} bytes from Nexus", size);

var data = _tcpDataSocketStream.ReadExactly(size, _logger);

return new CastMemoryManager<byte, double>(data).Memory;
}

private int ReadSize(NetworkStream currentStream)
{
var sizeBuffer = currentStream.ReadExactly(4);
var sizeBuffer = currentStream.ReadExactly(4, _logger);
Array.Reverse(sizeBuffer);

var size = BitConverter.ToInt32(sizeBuffer);
Expand Down Expand Up @@ -403,7 +406,7 @@ public static async Task SendToServerAsync(JsonNode response, NetworkStream curr

internal static class StreamExtensions
{
public static byte[] ReadExactly(this Stream stream, int count)
public static byte[] ReadExactly(this Stream stream, int count, ILogger logger)
{
var buffer = new byte[count];
var offset = 0;
Expand All @@ -413,7 +416,10 @@ public static byte[] ReadExactly(this Stream stream, int count)
var read = stream.Read(buffer, offset, count - offset);

if (read == 0)
{
logger.LogDebug("No data from Nexus received (exiting)");
Environment.Exit(0);
}

offset += read;
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.2",
"version": "1.0.3",
"suffix": ""
}

0 comments on commit 89b7240

Please sign in to comment.