servicepoint/crates/servicepoint_binding_cs/ServicePoint/Connection.cs

36 lines
792 B
C#
Raw Normal View History

2024-05-13 00:17:40 +02:00
using System.Text;
using ServicePoint.BindGen;
2024-05-13 00:17:40 +02:00
namespace ServicePoint;
2024-05-13 00:17:40 +02:00
public sealed class Connection : SpNativeInstance<BindGen.Connection>
2024-05-13 00:17:40 +02:00
{
public static Connection Open(string host)
{
unsafe
{
fixed (byte* bytePtr = Encoding.UTF8.GetBytes(host))
{
return new Connection(NativeMethods.sp_connection_open(bytePtr));
2024-05-13 00:17:40 +02:00
}
}
}
public bool Send(Packet packet)
2024-05-13 00:17:40 +02:00
{
unsafe
{
return NativeMethods.sp_connection_send(Instance, packet.Into());
2024-05-13 00:17:40 +02:00
}
}
private protected override unsafe void Dealloc()
2024-05-13 00:17:40 +02:00
{
NativeMethods.sp_connection_dealloc(Instance);
2024-05-13 00:17:40 +02:00
}
private unsafe Connection(BindGen.Connection* instance) : base(instance)
{
}
}