Adding Receive (it's crashing because it needs to be an array of intptr)

This commit is contained in:
Garry Newman 2019-05-03 16:47:29 +01:00
parent 91083d5d16
commit 3b2c7a5a16
2 changed files with 37 additions and 1 deletions

View File

@ -99,6 +99,7 @@ namespace Steamworks
while ( Connected )
{
Receive();
await Task.Delay( 10 );
}
}

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using Steamworks.Data;
namespace Steamworks
@ -64,5 +66,38 @@ namespace Steamworks
{
Connected = false;
}
SteamNetworkingMessage_t[] messageBuffer;
public void Receive()
{
if ( messageBuffer == null )
{
messageBuffer = new SteamNetworkingMessage_t[128];
}
var processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnConnection( Connection, ref messageBuffer, messageBuffer.Length );
for ( int i=0; i< processed; i++ )
{
Console.WriteLine( "FOUND SOME!" );
ReceiveMessage( messageBuffer[i] );
}
//
// Overwhelmed our buffer, keep going
//
if ( processed == messageBuffer.Length )
Receive();
}
internal unsafe void ReceiveMessage( SteamNetworkingMessage_t msg )
{
var stream = new UnmanagedMemoryStream( (byte*)msg.data, msg.length, msg.length, FileAccess.Read );
// read Message
msg.release.Invoke( ref msg );
}
}
}