Exemple #1
0
        private unsafe static int StaticHandler(QuicHandle *handle, void *context, QuicNativeConnectionEvent *evnt)
        {
            var managedHandle = GCHandle.FromIntPtr((IntPtr)context);
            var connection    = (QuicConnection)managedHandle.Target;

            return(connection.Handler(evnt));
        }
        internal unsafe QuicRegistration(QuicRegistrationConfig config, IQuicInteropApi nativeApi)
        {
            m_nativeApi = nativeApi;
            QuicHandle *handle = null;
            QuicNativeRegistrationConfig nativeRegConfig = new QuicNativeRegistrationConfig
            {
                AppName          = null,
                ExecutionProfile = config.ExecutionProfile
            };

            if (config.AppName != null)
            {
                int         appNameLength    = config.AppName.Length;
                int         maxAppNameLength = Encoding.UTF8.GetMaxByteCount(appNameLength);
                Span <byte> appNameSpan      = appNameLength < 256 ? stackalloc byte[256] : new byte[maxAppNameLength];

                fixed(byte *appNamePtr = appNameSpan)
                {
                    fixed(char *strNamePtr = config.AppName)
                    {
                        int actualLength = Encoding.UTF8.GetBytes(strNamePtr, appNameLength, appNamePtr, maxAppNameLength);

                        appNameSpan[actualLength] = 0; // null terminator
                    }

                    nativeRegConfig.AppName = appNamePtr;
                    m_nativeApi.RegistrationOpen(&nativeRegConfig, &handle);
                }
            }
            else
            {
                m_nativeApi.RegistrationOpen(&nativeRegConfig, &handle);
            }
            m_handle = handle;
        }
Exemple #3
0
        private unsafe static int StaticHandler(QuicHandle *handle, void *context, QuicNativeListenerEvent *evnt)
        {
            var managedHandle = GCHandle.FromIntPtr((IntPtr)context);
            var listener      = (QuicListener)managedHandle.Target;

            return(listener.Handler(evnt));
        }
Exemple #4
0
        internal unsafe QuicSession(IQuicInteropApi nativeApi, QuicRegistration registration, byte[][] apln)
        {
            m_nativeApi = nativeApi;

            QuicHandle *handle = null;

            QuicNativeBuffer *buffers = stackalloc QuicNativeBuffer[apln.Length];

            try
            {
                for (int i = 0; i < apln.Length; i++)
                {
                    byte *allocated = (byte *)Marshal.AllocHGlobal((IntPtr)apln[i].Length);
                    buffers[i].Buffer = allocated;
                    buffers[i].Length = (uint)apln[i].Length;
                    apln[i].AsSpan().CopyTo(new Span <byte>(allocated, apln[i].Length));
                }

                m_nativeApi.SessionOpen(registration.m_handle, buffers, (uint)apln.Length, null, &handle);
                m_handle = handle;
            }
            finally
            {
                for (int i = 0; i < apln.Length; i++)
                {
                    Marshal.FreeHGlobal((IntPtr)buffers[i].Buffer);
                }
            }
        }
        internal unsafe QuicRegistration(IQuicInteropApi nativeApi)
        {
            m_nativeApi = nativeApi;
            QuicHandle *handle = null;

            m_nativeApi.RegistrationOpen(null, &handle);
            m_handle = handle;
        }
Exemple #6
0
        internal unsafe QuicConnection(IQuicInteropApi api, QuicSession session)
        {
            m_nativeApi = api;
            QuicHandle *handle = null;

            api.ConnectionOpen(session.m_handle, null, null, &handle);
            m_handle = handle;
        }
Exemple #7
0
        internal unsafe QuicListener(IQuicInteropApi nativeApi, QuicSession session)
        {
            m_nativeApi = nativeApi;
            m_session   = session;

            connectionQueue = Channel.CreateBounded <QuicConnection>(new BoundedChannelOptions(128)
            {
                SingleWriter = true,
                SingleReader = true,
            });

            m_gcHandle = GCHandle.Alloc(this);

            QuicHandle *handle = null;

            m_nativeApi.ListenerOpen(session.m_handle, m_nativeListenerCallback, (void *)GCHandle.ToIntPtr(m_gcHandle), &handle);

            m_handle = handle;
        }