2024-05-13 00:17:40 +02:00
|
|
|
|
using System.Text;
|
2024-05-25 11:16:37 +02:00
|
|
|
|
using ServicePoint.BindGen;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
|
2024-05-25 11:16:37 +02:00
|
|
|
|
namespace ServicePoint;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
|
2024-05-25 11:16:37 +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.sp2_connection_open(bytePtr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
|
public bool Send(Packet packet)
|
2024-05-13 00:17:40 +02:00
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-05-15 20:34:51 +02:00
|
|
|
|
return NativeMethods.sp2_connection_send(Instance, packet.Into());
|
2024-05-13 00:17:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
|
private protected override unsafe void Dealloc()
|
2024-05-13 00:17:40 +02:00
|
|
|
|
{
|
|
|
|
|
NativeMethods.sp2_connection_dealloc(Instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private unsafe Connection(BindGen.Connection* instance) : base(instance)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|