// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; namespace FlaxEngine { partial class Platform { /// /// Checks if current execution in on the main thread. /// public static bool IsInMainThread => CurrentThreadID == Globals.MainThreadID; } partial class Network { /// /// Writes data to the socket. /// /// The socket. /// The data to write. /// Returns -1 on error, otherwise bytes written. [Unmanaged] public static unsafe int WriteSocket(NetworkSocket socket, byte[] data) { if (data == null) throw new ArgumentNullException(nameof(data)); fixed (byte* ptr = data) return Internal_WriteSocket(ref socket, ptr, (uint)data.Length, null); } /// /// Writes data to the socket. /// /// The socket. /// The data to write. /// If protocol is UDP, the destination end point. /// Returns -1 on error, otherwise bytes written. [Unmanaged] public static unsafe int WriteSocket(NetworkSocket socket, byte[] data, NetworkEndPoint endPoint) { if (data == null) throw new ArgumentNullException(nameof(data)); fixed (byte* ptr = data) return Internal_WriteSocket(ref socket, ptr, (uint)data.Length, &endPoint); } /// /// Reads data on the socket. /// /// The socket. /// The buffer. /// Returns -1 on error, otherwise bytes read. [Unmanaged] public static unsafe int ReadSocket(NetworkSocket socket, byte[] buffer) { if (buffer == null) throw new ArgumentNullException(nameof(buffer)); fixed (byte* ptr = buffer) return Internal_ReadSocket(ref socket, ptr, (uint)buffer.Length, null); } /// /// Reads data on the socket. /// /// The socket. /// The buffer. /// If UDP, the end point from where data is coming. Otherwise nullptr. /// Returns -1 on error, otherwise bytes read. [Unmanaged] public static unsafe int ReadSocket(NetworkSocket socket, byte[] buffer, NetworkEndPoint endPoint) { if (buffer == null) throw new ArgumentNullException(nameof(buffer)); fixed (byte* ptr = buffer) return Internal_ReadSocket(ref socket, ptr, (uint)buffer.Length, &endPoint); } } }