Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET NORM Extension #85

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3a20a8b
.NET Extension Design (#5)
mullerj Feb 9, 2023
2694446
.NET Extension Design Implementation (#10)
mullerj Mar 1, 2023
701360a
NormSession typos in comments (#12)
mullerj Mar 10, 2023
db20c64
Feature/9 net norm extension target architecture packages (#13)
mullerj Mar 13, 2023
86d8fb1
Merge branch 'USNavalResearchLaboratory:master' into master
mullerj Jun 19, 2023
96476ff
Codespace Configurations (#15)
mullerj Jun 21, 2023
a1dcbf1
.NET norm extension GitHub actions (#16)
mullerj Jun 30, 2023
e60a3af
Update dotnet-publish.yml to use source branch (#18)
mullerj Jun 30, 2023
47bf91a
.NET norm package publish (#19)
mullerj Jul 4, 2023
7d7de23
Publish test results (#21)
mullerj Jul 4, 2023
2d8768c
Dev Container extensions (#23)
mullerj Jul 4, 2023
2be146c
Dev Container performance (#25)
mullerj Jul 4, 2023
43c0736
Revert "Dev Container performance (#25)" (#27)
mullerj Jul 4, 2023
b04acd3
Merge branch 'USNavalResearchLaboratory:master' into master
mullerj Mar 28, 2024
034980e
Update action versions for dotnet-publish.yml
mullerj Mar 28, 2024
b5d2e87
Update action versions for dotnet.yml
mullerj Mar 28, 2024
1d91fde
Fixed ReceivesData test to use received events for actual data
mullerj May 22, 2024
3cdb415
NormData Refactor (#30)
mullerj May 27, 2024
edbcff7
NormDataEnqueue Refactor (#31)
mullerj May 28, 2024
b9c18c5
Updated GetSession to use lock
mullerj Jun 6, 2024
0662326
Updated GetSession to TryGetValue
mullerj Jun 6, 2024
662e1fa
DataEnqueue Refactor (#33)
mullerj Jun 14, 2024
0eb0b82
Merge branch 'USNavalResearchLaboratory:master' into master
mullerj Jun 14, 2024
d539a35
NormDataEnqueue Refactor (#34)
mullerj Jul 29, 2024
bc8ab6b
Updated NormFile.Name to use PtrToStringAnsi
mullerj Aug 23, 2024
f04faca
Updated NormFile.Name to use stackalloc (#37)
mullerj Aug 25, 2024
022e120
Updated NormNode.Address to use stackalloc and create IPAddress from …
mullerj Aug 25, 2024
32c3eb5
NormObject Refactor
mullerj Aug 28, 2024
6ae32b1
NormStream Refactor
mullerj Aug 28, 2024
e4513cc
NormNode Refactor
mullerj Aug 28, 2024
3ee6345
NormFile Refactor
mullerj Aug 28, 2024
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
10 changes: 5 additions & 5 deletions src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class NormApi <<static>> {
+ {static} <<extern>> NormRequeueObject(sessionHandle:long, objectHandle:long) : bool
+ {static} <<extern>> NormStreamOpen(sessionHandle:long, bufferSize:long, infoPtr:nint, infoLen:int) : long
+ {static} <<extern>> NormStreamClose(streamHandle:long, graceful:bool) : void
<<internal>> {static} <<extern>> NormStreamWrite(streamHandle:long, buffer:nint, numBytes:int) : int
+ <<unsafe>> {static} <<extern>> NormStreamWrite(streamHandle:long, buffer:byte*, numBytes:int) : int
+ {static} <<extern>> NormStreamFlush(streamHandle:long, eom:bool, flushMode:NormFlushMode) : void
+ {static} <<extern>> NormStreamSetAutoFlush(streamHandle:long, flushMode:NormFlushMode) : void
+ {static} <<extern>> NormStreamSetPushEnable(streamHandle:long, pushEnable:bool) : void
Expand Down Expand Up @@ -85,7 +85,7 @@ class NormApi <<static>> {
+ {static} <<extern>> NormNodeSetRepairBoundary(remoteSender:long, repairBoundary:NormRepairBoundary) : void
+ {static} <<extern>> NormSetDefaultRxRobustFactor(sessionHandle:long, robustFactor:int) : void
+ {static} <<extern>> NormNodeSetRxRobustFactor(remoteSender:long, robustFactor:int) : void
+ {static} <<extern>> NormStreamRead(streamHandle:long, buffer:nint, numBytes:int) : bool
+ <<unsafe>> {static} <<extern>> NormStreamRead(streamHandle:long, buffer:byte*, numBytes:int) : bool
+ {static} <<extern>> NormStreamSeekMsgStart(streamHandle:long) : bool
+ {static} <<extern>> NormStreamGetReadOffset(streamHandle:long) : long
+ {static} <<extern>> NormObjectGetType(objectHandle:long) : NormObjectType
Expand All @@ -97,14 +97,14 @@ class NormApi <<static>> {
+ {static} <<extern>> NormObjectCancel(objectHandle:long) : void
+ {static} <<extern>> NormObjectRetain(objectHandle:long) : void
+ {static} <<extern>> NormObjectRelease(objectHandle:long) : void
+ {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:nint, bufferLen:int) : bool
+ <<unsafe>> {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:sbyte*, bufferLen:int) : bool
+ {static} <<extern>> NormFileRename(fileHandle:long, fileName:string) : bool
+ {static} <<extern>> NormDataAccessData(objectHandle:long) : nint
+ {static} <<extern>> NormObjectGetSender(objectHandle:long) : long
+ {static} <<extern>> NormNodeGetId(nodeHandle:long) : long
+ {static} <<extern>> NormNodeGetAddress(nodeHandle:long, addrBuffer:nint, bufferLen:int, port:int) : bool
+ <<unsafe>> {static} <<extern>> NormNodeGetAddress(nodeHandle:long, addrBuffer:byte*, bufferLen:int, port:int) : bool
+ {static} <<extern>> NormNodeGetGrtt(nodeHandle:long) : double
+ {static} <<extern>> NormNodeGetCommand(remoteSender:long, cmdBuffer:nint, buflen:int) : bool
+ <<unsafe>> {static} <<extern>> NormNodeGetCommand(remoteSender:long, cmdBuffer:byte*, buflen:int) : bool
+ {static} <<extern>> NormNodeFreeBuffers(remoteSender:long) : void
+ {static} <<extern>> NormNodeRetain(nodeHandle:long) : void
+ {static} <<extern>> NormNodeRelease(nodeHandle:long) : void
Expand Down
10 changes: 5 additions & 5 deletions src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public struct NormEvent
/// <param name="numBytes">The numBytes parameter indicates the length of the data content.</param>
/// <returns>This function returns the number of bytes of data successfully enqueued for NORM stream transmission.</returns>
[DllImport(NORM_LIBRARY)]
internal static extern int NormStreamWrite(long streamHandle, nint buffer, int numBytes);
public unsafe static extern int NormStreamWrite(long streamHandle, byte* buffer, int numBytes);

/// <summary>
/// This function causes an immediate "flush" of the transmit stream specified by the streamHandle parameter.
Expand Down Expand Up @@ -895,7 +895,7 @@ public struct NormEvent
/// <returns>This function normally returns a value of true. However, if a break in the integrity of the reliable received stream
/// occurs(or the stream has been ended by the sender), a value of false is returned to indicate the break. </returns>
[DllImport(NORM_LIBRARY)]
public static extern bool NormStreamRead(long streamHandle, nint buffer, ref int numBytes);
public unsafe static extern bool NormStreamRead(long streamHandle, byte* buffer, ref int numBytes);

/// <summary>
/// This function advances the read offset of the receive stream referenced by the streamHandle parameter to align
Expand Down Expand Up @@ -1020,7 +1020,7 @@ public struct NormEvent
/// does not refer to an object of type NORM_OBJECT_FILE.
/// </returns>
[DllImport(NORM_LIBRARY)]
public static extern bool NormFileGetName(long fileHandle, nint nameBuffer, int bufferLen);
public unsafe static extern bool NormFileGetName(long fileHandle, sbyte* nameBuffer, int bufferLen);

/// <summary>
/// This function renames the file used to store content for the NORM_OBJECT_FILE transport object specified by
Expand Down Expand Up @@ -1081,7 +1081,7 @@ public struct NormEvent
/// <param name="port">port number and/or specify a specific source address binding that is used for packet transmission.</param>
/// <returns>A value of true is returned upon success and false upon failure. An invalid nodeHandle parameter value would lead to such failure.</returns>
[DllImport(NORM_LIBRARY)]
public static extern bool NormNodeGetAddress(long nodeHandle, nint addrBuffer, ref int bufferLen, out int port);
public unsafe static extern bool NormNodeGetAddress(long nodeHandle, byte* addrBuffer, ref int bufferLen, out int port);

/// <summary>
/// This function retrieves the advertised estimate of group round-trip timing (GRTT) for the remote sender referenced by the given nodeHandle value.
Expand All @@ -1104,7 +1104,7 @@ public struct NormEvent
/// either no command was available or the provided buffer size (buflen parameter) was inadequate.
/// The value referenced by the buflen parameter is adjusted to indicate the actual command length (in bytes) upon return.</returns>
[DllImport(NORM_LIBRARY)]
public static extern bool NormNodeGetCommand(long remoteSender, nint cmdBuffer, ref int buflen);
public unsafe static extern bool NormNodeGetCommand(long remoteSender, byte* cmdBuffer, ref int buflen);

/// <summary>
/// This function releases memory resources that were allocated for a remote sender.
Expand Down
15 changes: 5 additions & 10 deletions src/dotnet/src/Mil.Navy.Nrl.Norm/NormFile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Mil.Navy.Nrl.Norm
namespace Mil.Navy.Nrl.Norm
{
/// <summary>
/// A transport object of type NORM_OBJECT_FILE.
Expand Down Expand Up @@ -29,16 +26,14 @@ public unsafe string Name
{
get
{
var buffer = stackalloc byte[FILENAME_MAX];
var bufferPtr = (nint)buffer;
var buffer = stackalloc sbyte[FILENAME_MAX];

if (!NormFileGetName(_handle, bufferPtr, FILENAME_MAX))
if (!NormFileGetName(_handle, buffer, FILENAME_MAX))
{
throw new IOException("Failed to get file name");
}
var name = Marshal.PtrToStringAnsi(bufferPtr);

return name ?? string.Empty;

return new string(buffer);
}
mullerj marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
21 changes: 8 additions & 13 deletions src/dotnet/src/Mil.Navy.Nrl.Norm/NormNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net;
using System.Runtime.InteropServices;

namespace Mil.Navy.Nrl.Norm
{
Expand Down Expand Up @@ -48,9 +47,8 @@ public unsafe IPEndPoint Address
{
var bufferLength = 256;
var buffer = stackalloc byte[bufferLength];
var addrBuffer = (nint)buffer;

if (!NormNodeGetAddress(_handle, addrBuffer, ref bufferLength, out int port))
if (!NormNodeGetAddress(_handle, buffer, ref bufferLength, out int port))
{
throw new IOException("Failed to get node address");
}
Expand Down Expand Up @@ -81,20 +79,17 @@ public int GetCommand(byte[] buffer, int offset, int length)
throw new ArgumentOutOfRangeException(nameof(length), "The length is out of range");
}

var bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

try
unsafe
{
var bufferPtr = bufferHandle.AddrOfPinnedObject() + offset;
if (!NormNodeGetCommand(_handle, bufferPtr, ref length))
fixed (byte* bufferPtr = buffer)
{
throw new IOException("Failed to get command");
if (!NormNodeGetCommand(_handle, bufferPtr + offset, ref length))
{
throw new IOException("Failed to get command");
}
}
}
finally
{
bufferHandle.Free();
}

return length;
}

Expand Down
34 changes: 12 additions & 22 deletions src/dotnet/src/Mil.Navy.Nrl.Norm/NormStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.InteropServices;

namespace Mil.Navy.Nrl.Norm
namespace Mil.Navy.Nrl.Norm
{
/// <summary>
/// A transport object of type NORM_OBJECT_STREAM.
Expand Down Expand Up @@ -59,16 +57,12 @@ public int Write(byte[] buffer, int offset, int length)
}

int numBytes;
var bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

try
unsafe
{
var bufferPtr = bufferHandle.AddrOfPinnedObject() + offset;
numBytes = NormStreamWrite(_handle, bufferPtr, length);
}
finally
{
bufferHandle.Free();
fixed (byte* bufferPtr = buffer)
{
numBytes = NormStreamWrite(_handle, bufferPtr + offset, length);
}
}

return numBytes;
Expand Down Expand Up @@ -158,20 +152,16 @@ public int Read(byte[] buffer, int offset, int length)
throw new ArgumentOutOfRangeException(nameof(length), "The length is out of range");
}

var bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

try
unsafe
{
var bufferPtr = bufferHandle.AddrOfPinnedObject() + offset;
if (!NormStreamRead(_handle, bufferPtr, ref length))
fixed (byte* bufferPtr = buffer)
{
length = -1;
if (!NormStreamRead(_handle, bufferPtr + offset, ref length))
{
length = -1;
}
}
}
finally
{
bufferHandle.Free();
}

return length;
}
Expand Down
Loading