null check

This commit is contained in:
JohnCorby 2025-02-25 02:39:57 -08:00
parent 48e450b4dc
commit a4638861e3
3 changed files with 5 additions and 34 deletions

View File

@ -88,20 +88,6 @@ public class Client
public void Send(ArraySegment<byte> segment, int channelId)
{
// from fizzy
var data = new byte[segment.Count];
Array.Copy(segment.Array, segment.Offset, data, 0, data.Length);
var pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
var pData = pinnedArray.AddrOfPinnedObject();
var result = SteamNetworkingSockets.SendMessageToConnection(_conn, pData, (uint)data.Length, Util.MirrorChannel2SendFlag(channelId), out _);
if (result == EResult.k_EResultOK)
_transport.OnClientDataSent?.Invoke(segment, channelId);
else
_transport.OnClientError?.Invoke(TransportError.InvalidSend, $"send returned {result}");
// i dont think we have to check for disconnect result here since the status change handles that
/*
// use pointer to managed array instead of making copy. is this okay?
unsafe
{
@ -115,7 +101,6 @@ public class Client
// i dont think we have to check for disconnect result here since the status change handles that
}
}
*/
}
public void Receive()

View File

@ -78,20 +78,6 @@ public class Server
{
var conn = new HSteamNetConnection((uint)connectionId);
// from fizzy
var data = new byte[segment.Count];
Array.Copy(segment.Array, segment.Offset, data, 0, data.Length);
var pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
var pData = pinnedArray.AddrOfPinnedObject();
var result = SteamNetworkingSockets.SendMessageToConnection(conn, pData, (uint)data.Length, Util.MirrorChannel2SendFlag(channelId), out _);
if (result == EResult.k_EResultOK)
_transport.OnServerDataSent?.Invoke(connectionId, segment, channelId);
else
_transport.OnServerError?.Invoke(connectionId, TransportError.InvalidSend, $"send returned {result}");
// i dont think we have to check for disconnect result here since the status change handles that
/*
// use pointer to managed array instead of making copy. is this okay?
unsafe
{
@ -105,7 +91,6 @@ public class Server
// i dont think we have to check for disconnect result here since the status change handles that
}
}
*/
}
public void Receive()

View File

@ -96,23 +96,24 @@ public class SteamTransport : Transport
}
}
// all of these update functions run all the time, so we must null check
public override void ClientEarlyUpdate()
{
_client.Receive();
_client?.Receive();
}
public override void ServerEarlyUpdate()
{
_server.Receive();
_server?.Receive();
}
public override void ClientLateUpdate()
{
_client.Flush();
_client?.Flush();
}
public override void ServerLateUpdate()
{
_server.Flush();
_server?.Flush();
}
}