Example #1
0
        static void TrampolineReceiveCompletionReadOnlyData(IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, bool isComplete, IntPtr error)
        {
            var del = BlockLiteral.GetTarget <NWConnectionReceiveReadOnlySpanCompletion> (block);

            if (del != null)
            {
                DispatchData dispatchData = null, dataCopy = null;
                IntPtr       bufferAddress = IntPtr.Zero;
                nuint        bufferSize    = 0;

                if (dispatchDataPtr != IntPtr.Zero)
                {
                    dispatchData = new DispatchData(dispatchDataPtr, owns: false);
                    dataCopy     = dispatchData.CreateMap(out bufferAddress, out bufferSize);
                }

                unsafe {
                    var spanData = new ReadOnlySpan <byte> ((void *)bufferAddress, (int)bufferSize);
                    del(spanData,
                        contentContext == IntPtr.Zero ? null : new NWContentContext(contentContext, owns: false),
                        isComplete,
                        error == IntPtr.Zero ? null : new NWError(error, owns: false));
                }

                if (dispatchData != null)
                {
                    dataCopy.Dispose();
                    dispatchData.Dispose();
                }
            }
        }
Example #2
0
        static void TrampolineReceiveCompletion(IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, bool isComplete, IntPtr error)
        {
            var del = BlockLiteral.GetTarget <NWConnectionReceiveCompletion> (block);

            if (del != null)
            {
                DispatchData?dispatchData = null, dataCopy = null;
                IntPtr       bufferAddress = IntPtr.Zero;
                nuint        bufferSize    = 0;

                if (dispatchDataPtr != IntPtr.Zero)
                {
                    dispatchData = new DispatchData(dispatchDataPtr, owns: false);
                    dataCopy     = dispatchData.CreateMap(out bufferAddress, out bufferSize);
                }

                del(bufferAddress,
                    bufferSize,
                    contentContext == IntPtr.Zero ? null : new NWContentContext(contentContext, owns: false),
                    isComplete,
                    error == IntPtr.Zero ? null : new NWError(error, owns: false));

                if (dispatchData != null)
                {
                    dataCopy?.Dispose();
                    dispatchData?.Dispose();
                }
            }
        }