internal static unsafe void SetULongParam(MsQuicApi api, MsQuicSafeHandle nativeObject, uint param, ulong value) { ThrowIfFailure(api.ApiTable->SetParam( nativeObject.QuicHandle, param, sizeof(ulong), (byte *)&value), "Could not set ulong"); }
internal static unsafe ulong GetULongParam(MsQuicApi api, MsQuicSafeHandle nativeObject, uint param) { ulong value; uint valueLen = (uint)sizeof(ulong); ThrowIfFailure(api.ApiTable->GetParam( nativeObject.QuicHandle, param, &valueLen, (byte *)&value), "GetULongParam failed"); Debug.Assert(valueLen == sizeof(ulong)); return(value); }
internal static unsafe void SetIPEndPointParam(MsQuicApi api, MsQuicSafeHandle nativeObject, uint param, IPEndPoint value) { Internals.SocketAddress socketAddress = IPEndPointExtensions.Serialize(value); // MsQuic always reads same amount of memory as if IPv6 was used, so we can't pass pointer to socketAddress.Buffer directly Span <byte> address = stackalloc byte[Internals.SocketAddress.IPv6AddressSize]; socketAddress.Buffer.AsSpan(0, socketAddress.Size).CopyTo(address); address.Slice(socketAddress.Size).Clear(); fixed(byte *paddress = &MemoryMarshal.GetReference(address)) { ThrowIfFailure(api.ApiTable->SetParam( nativeObject.QuicHandle, param, (uint)address.Length, paddress), "Could not set IPEndPoint"); } }
internal static unsafe IPEndPoint GetIPEndPointParam(MsQuicApi api, MsQuicSafeHandle nativeObject, uint param) { // MsQuic always uses storage size as if IPv6 was used uint valueLen = (uint)Internals.SocketAddress.IPv6AddressSize; Span <byte> address = stackalloc byte[Internals.SocketAddress.IPv6AddressSize]; fixed(byte *paddress = &MemoryMarshal.GetReference(address)) { ThrowIfFailure(api.ApiTable->GetParam( nativeObject.QuicHandle, param, &valueLen, paddress), "GetIPEndPointParam failed."); } address = address.Slice(0, (int)valueLen); return(new Internals.SocketAddress(SocketAddressPal.GetAddressFamily(address), address).GetIPEndPoint()); }