mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-12-11 20:15:10 +01:00
dont copy on send
This commit is contained in:
parent
83a912e7c4
commit
d711202dae
@ -69,13 +69,12 @@ public class Client
|
||||
|
||||
public void Send(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
var data = new byte[segment.Count];
|
||||
Array.Copy(segment.Array, segment.Offset, data, 0, data.Length);
|
||||
// use pointer to managed array instead of making copy. is this okay?
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
fixed (byte* pData = segment.Array)
|
||||
{
|
||||
var result = SteamNetworkingSockets.SendMessageToConnection(_conn, (IntPtr)pData, (uint)data.Length, Util.MirrorChannel2SendFlag(channelId), out _);
|
||||
var result = SteamNetworkingSockets.SendMessageToConnection(_conn, (IntPtr)(pData + segment.Offset), (uint)segment.Count, Util.MirrorChannel2SendFlag(channelId), out _);
|
||||
_transport.OnClientDataSent?.Invoke(segment, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public static class Program
|
||||
running = false;
|
||||
break;
|
||||
case 's':
|
||||
transport.ServerSend(theConn, new ArraySegment<byte>(new byte[] { 1, 2, 3 }));
|
||||
transport.ServerSend(theConn, new ArraySegment<byte>(new byte[] { 1, 2, 3, 4, 5 }, 1, 5 - 1));
|
||||
break;
|
||||
case 'd':
|
||||
transport.ServerDisconnect(theConn);
|
||||
@ -136,7 +136,7 @@ public static class Program
|
||||
running = false;
|
||||
break;
|
||||
case 's':
|
||||
transport.ClientSend(new ArraySegment<byte>(new byte[] { 1, 2, 3 }));
|
||||
transport.ClientSend(new ArraySegment<byte>(new byte[] { 1, 2, 3, 4, 5 }, 1, 5 - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ public class Server
|
||||
|
||||
public bool IsListening;
|
||||
private HSteamListenSocket _listenSocket;
|
||||
// connection id is derived from uint to int cast here. is that okay???
|
||||
private readonly List<HSteamNetConnection> _conns = new();
|
||||
|
||||
public void StartListening()
|
||||
@ -62,13 +63,12 @@ public class Server
|
||||
{
|
||||
var conn = new HSteamNetConnection((uint)connectionId);
|
||||
|
||||
var data = new byte[segment.Count];
|
||||
Array.Copy(segment.Array, segment.Offset, data, 0, data.Length);
|
||||
// use pointer to managed array instead of making copy. is this okay?
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* pData = data)
|
||||
fixed (byte* pData = segment.Array)
|
||||
{
|
||||
var result = SteamNetworkingSockets.SendMessageToConnection(conn, (IntPtr)pData, (uint)data.Length, Util.MirrorChannel2SendFlag(channelId), out _);
|
||||
var result = SteamNetworkingSockets.SendMessageToConnection(conn, (IntPtr)(pData + segment.Offset), (uint)segment.Count, Util.MirrorChannel2SendFlag(channelId), out _);
|
||||
_transport.OnServerDataSent?.Invoke(connectionId, segment, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user