Skip to content

Commit

Permalink
Fix error due to writing an int rather than a byte
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Jul 6, 2024
1 parent 2260425 commit c5f5b4e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/SponsorLink/SponsorLink/DiagnosticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void ReportOnce(Action<Diagnostic> report, string product = Funding.Produ
using var accessor = mmf.CreateViewAccessor();
if (accessor.ReadByte(0) == 0)
{
accessor.Write(0, 1);
accessor.Write(0, (byte)1);
report(diagnostic);
Tracing.Trace($"👈{diagnostic.Severity.ToString().ToLowerInvariant()}:{Process.GetCurrentProcess().Id}:{Process.GetCurrentProcess().ProcessName}:{product}:{diagnostic.Id}");
}
Expand Down Expand Up @@ -182,7 +182,7 @@ Diagnostic Push(Diagnostic diagnostic, string product = Funding.Product)
mutex.WaitOne();
using var mmf = CreateOrOpenMemoryMappedFile(id, 1);
using var accessor = mmf.CreateViewAccessor();
accessor.Write(0, 0);
accessor.Write(0, (byte)0);
Tracing.Trace($"👉{diagnostic.Severity.ToString().ToLowerInvariant()}:{Process.GetCurrentProcess().Id}:{Process.GetCurrentProcess().ProcessName}:{product}:{diagnostic.Id}");
}

Expand All @@ -201,7 +201,7 @@ Diagnostic Push(Diagnostic diagnostic, string product = Funding.Product)
}
: null;

static MemoryMappedFile CreateOrOpenMemoryMappedFile(string mapName, long capacity)
static MemoryMappedFile CreateOrOpenMemoryMappedFile(string mapName, int capacity)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -210,7 +210,11 @@ static MemoryMappedFile CreateOrOpenMemoryMappedFile(string mapName, long capaci
else
{
// On Linux, use a file-based memory-mapped file
return MemoryMappedFile.CreateFromFile($"/tmp/{mapName}", FileMode.OpenOrCreate);
string filePath = $"/tmp/{mapName}";
using (var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
fs.Write(new byte[capacity], 0, capacity);

return MemoryMappedFile.CreateFromFile(filePath, FileMode.OpenOrCreate);
}
}

Expand Down

0 comments on commit c5f5b4e

Please sign in to comment.