Added optional receiveToEnd toggle to ConnectionManager.Receive and SocketManager.Receive (default true = old behaviour)

This commit is contained in:
André Straubmeier 2020-11-19 13:44:51 +01:00
parent b4de0927f3
commit ea3743bd73
2 changed files with 10 additions and 6 deletions

View File

@ -109,7 +109,7 @@ namespace Steamworks
Interface?.OnDisconnected( info ); Interface?.OnDisconnected( info );
} }
public void Receive( int bufferSize = 32 ) public int Receive( int bufferSize = 32, bool receiveToEnd = true )
{ {
int processed = 0; int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize ); IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
@ -131,8 +131,10 @@ namespace Steamworks
// //
// Overwhelmed our buffer, keep going // Overwhelmed our buffer, keep going
// //
if ( processed == bufferSize ) if ( receiveToEnd && processed == bufferSize )
Receive( bufferSize ); processed += Receive( bufferSize );
return processed;
} }
internal unsafe void ReceiveMessage( IntPtr msgPtr ) internal unsafe void ReceiveMessage( IntPtr msgPtr )

View File

@ -123,7 +123,7 @@ namespace Steamworks
} }
} }
public void Receive( int bufferSize = 32 ) public int Receive( int bufferSize = 32, bool receiveToEnd = true )
{ {
int processed = 0; int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize ); IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
@ -146,8 +146,10 @@ namespace Steamworks
// //
// Overwhelmed our buffer, keep going // Overwhelmed our buffer, keep going
// //
if ( processed == bufferSize ) if ( receiveToEnd && processed == bufferSize )
Receive( bufferSize ); processed += Receive( bufferSize );
return processed;
} }
internal unsafe void ReceiveMessage( IntPtr msgPtr ) internal unsafe void ReceiveMessage( IntPtr msgPtr )