mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
Make SendMessage call SendMessages instead of SendMessageToConnection
This commit is contained in:
parent
28effd140b
commit
5c11508f41
@ -48,7 +48,7 @@ public bool Decrement()
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
|
||||
private delegate void FreeFn( NetMsg* msg );
|
||||
|
||||
private static readonly Stack<ReferenceCounter> ReferenceCounterPool =
|
||||
@ -246,7 +246,7 @@ private static void FreeBuffer( IntPtr ptr, int size )
|
||||
}
|
||||
}
|
||||
|
||||
private const int Bucket512 = 512;
|
||||
private const int Bucket512 = 512;
|
||||
private const int Bucket1Kb = 1 * 1024;
|
||||
private const int Bucket4Kb = 4 * 1024;
|
||||
private const int Bucket16Kb = 16 * 1024;
|
||||
@ -254,8 +254,8 @@ private static void FreeBuffer( IntPtr ptr, int size )
|
||||
private const int Bucket256Kb = 256 * 1024;
|
||||
|
||||
private static int GetBucketSize( int size )
|
||||
{
|
||||
if ( size <= Bucket512 ) return Bucket512;
|
||||
{
|
||||
if ( size <= Bucket512 ) return Bucket512;
|
||||
if ( size <= Bucket1Kb ) return Bucket1Kb;
|
||||
if ( size <= Bucket4Kb ) return Bucket4Kb;
|
||||
if ( size <= Bucket16Kb ) return Bucket16Kb;
|
||||
|
@ -65,11 +65,30 @@ public string ConnectionName
|
||||
/// <summary>
|
||||
/// This is the best version to use.
|
||||
/// </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;
|
||||
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>
|
||||
/// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and
|
||||
|
Loading…
Reference in New Issue
Block a user