Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Parse goesrecv symbols to remove stray nanomsg headers #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions goesrecv-monitor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3")]
[assembly: AssemblyFileVersion("1.3")]
[assembly: AssemblyVersion("1.3.1")]
[assembly: AssemblyFileVersion("1.3.1")]
32 changes: 29 additions & 3 deletions goesrecv-monitor/Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static void SymbolLoop()
Socket s = new Socket(SocketType.Stream, ProtocolType.Tcp);
Program.Log(logsrc, "Socket created");

byte[] res = new byte[8];
try
{
// Connect socket
Expand All @@ -57,7 +58,6 @@ static void SymbolLoop()
s.Send(nninit);

// Check nanomsg response
byte[] res = new byte[8];
int bytesRec = s.Receive(res);
if (res.SequenceEqual(nnires))
{
Expand All @@ -77,11 +77,12 @@ static void SymbolLoop()
}

byte[] dres = new byte[65536];
int num;
byte[] buffer = new byte[65536];
int num, remainingBytesToWrite, startReadingAt, totalBytes = 0, bytesBeforeHeader = 0;
while (true)
{
// Receive message content
num = s.Receive(dres);
num = s.Receive(buffer);

// Kill thread if no data received
if (num == 0)
Expand All @@ -98,9 +99,34 @@ static void SymbolLoop()
return;
}

//Parse nanomsg response to find headers and remove them
remainingBytesToWrite = num;
startReadingAt = 0;
while (remainingBytesToWrite > bytesBeforeHeader)
{
//Write Information before header
if (bytesBeforeHeader > 0)
{
Buffer.BlockCopy(buffer, startReadingAt, dres, totalBytes, bytesBeforeHeader);
totalBytes += bytesBeforeHeader;
}

//Get next nanomsg packet length
Array.Copy(buffer, bytesBeforeHeader + startReadingAt, res, 0, 8);
if (BitConverter.IsLittleEndian) Array.Reverse(res);
startReadingAt += bytesBeforeHeader + 8;
remainingBytesToWrite = num - startReadingAt;
bytesBeforeHeader = (int)BitConverter.ToUInt64(res, 0);
}

//No more headers in bytes we have; write the rest of the bytes
Buffer.BlockCopy(buffer, startReadingAt, dres, totalBytes, remainingBytesToWrite);
bytesBeforeHeader -= remainingBytesToWrite;

// Update UI
Program.MainWindow.DrawSymbols(dres);

totalBytes = 0;
Thread.Sleep(10);
}
}
Expand Down