Make SendMessage call SendMessages instead of SendMessageToConnection

This commit is contained in:
Rohan Singh 2021-01-20 09:57:07 -05:00
parent 28effd140b
commit 5c11508f41
2 changed files with 26 additions and 7 deletions

View File

@ -48,7 +48,7 @@ public bool Decrement()
} }
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer( CallingConvention.Cdecl )]
private delegate void FreeFn( NetMsg* msg ); private delegate void FreeFn( NetMsg* msg );
private static readonly Stack<ReferenceCounter> ReferenceCounterPool = private static readonly Stack<ReferenceCounter> ReferenceCounterPool =

View File

@ -65,10 +65,29 @@ public string ConnectionName
/// <summary> /// <summary>
/// This is the best version to use. /// This is the best version to use.
/// </summary> /// </summary>
public Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable ) public unsafe Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable )
{ {
if ( ptr == IntPtr.Zero )
throw new ArgumentNullException( nameof( ptr ) );
if ( size == 0 )
throw new ArgumentException( "`size` cannot be zero", nameof( size ) );
var copyPtr = BroadcastBufferManager.Get( size, 1 );
Buffer.MemoryCopy( (void*)ptr, (void*)copyPtr, size, size );
var message = SteamNetworkingUtils.AllocateMessage();
message->Connection = this;
message->Flags = sendType;
message->DataPtr = copyPtr;
message->DataSize = size;
message->FreeDataPtr = BroadcastBufferManager.FreeFunctionPointer;
long messageNumber = 0; long messageNumber = 0;
return SteamNetworkingSockets.Internal.SendMessageToConnection( this, ptr, (uint) size, (int)sendType, ref messageNumber ); SteamNetworkingSockets.Internal.SendMessages( 1, &message, &messageNumber );
return messageNumber >= 0
? Result.OK
: (Result)(-messageNumber);
} }
/// <summary> /// <summary>