NormStream Refactor
* Updated NormStream Write to use fixed statement * Updated NormStream Read to use fixed statement * Updated designpull/85/head
parent
32c3eb5239
commit
6ae32b1d0e
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ namespace Mil.Navy.Nrl.Norm
|
|||
/// <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.
|
||||
|
|
@ -895,7 +895,7 @@ namespace Mil.Navy.Nrl.Norm
|
|||
/// <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
|
||||
|
|
|
|||
|
|
@ -59,16 +59,12 @@ namespace Mil.Navy.Nrl.Norm
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
@ -158,20 +154,16 @@ namespace Mil.Navy.Nrl.Norm
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue