Esempio n. 1
0
 internal void Unpin()
 {
     // AppTrace.TraceSource.WriteNoise("ReliableSessionMessage.Unpin");
     this.pinCollection.Dispose();
     this.savedNativeMessageRef = null;
     Interlocked.Exchange(ref this.pinCollection, null);
 }
        unsafe private NativeRuntime.IFabricOperationData CreateNativeOperationData(IOperationData data, uint[] sizes)
        {
            NativeRuntime.IFabricOperationData operationData = null;
            using (var pin = new PinBlittable(sizes))
            {
                operationData = this.operationDataFactory.CreateOperationData(pin.AddrOfPinnedObject(), (uint)sizes.Length);
            }

            // get a pointer to the memory that native code allocated in the operation data it created for us
            uint   countAllocatedByNative;
            IntPtr nativeBuffersRaw = operationData.GetData(out countAllocatedByNative);

            ReleaseAssert.AssertIfNot(countAllocatedByNative == (uint)sizes.Length, StringResources.Error_BufferNumberMismatach);
            NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffers = (NativeTypes.FABRIC_OPERATION_DATA_BUFFER *)nativeBuffersRaw;

            // copy the data into the buffers allocated by native
            int index = 0;

            foreach (var item in data)
            {
                NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffer = nativeBuffers + index;
                ReleaseAssert.AssertIfNot(nativeBuffer->BufferSize == sizes[index], string.Format(CultureInfo.CurrentCulture, StringResources.Error_BufferAllocationSizeMismatch_Formatted, index, nativeBuffer->BufferSize, sizes[index]));

                Marshal.Copy(item.Array, item.Offset, nativeBuffer->Buffer, item.Count);
                index++;
            }

            return(operationData);
        }
Esempio n. 3
0
        private IOperationData ReceiveEndWrapper(NativeCommon.IFabricAsyncOperationContext context)
        {
            NativeRuntime.IFabricOperationData nativeReceiveMessage = null;
            // AppTrace.TraceSource.WriteNoise("NativeReliableSession.EndReceive");
            nativeReceiveMessage = this.nativeReliableSession.EndReceive(context);
            IOperationData result = new ReadOnlyOperationData(nativeReceiveMessage);

            return(new InboundMessage(result));
        }
Esempio n. 4
0
        internal static OperationData CreateFromNative(NativeRuntime.IFabricOperationData operationData)
        {
            // null operationData is already handled by the caller.
            Requires.Argument("operationData", operationData).NotNull();

            uint   count;
            IntPtr buffer = operationData.GetData(out count);

            return(OperationData.CreateFromNative(count, buffer));
        }
Esempio n. 5
0
        internal NativeRuntime.IFabricOperationData Pin(NativeReliableMessaging.IFabricMessageDataFactory messageDataFactory)
        {
            if (null != Interlocked.CompareExchange(ref this.pinCollection, new PinCollection(), null))
            {
                //
                // We do not allow the same ReliableSessionMessage object to be pinned concurrently.
                //
                throw new InvalidOperationException();
            }

            var sizes = this.originalMessage.Select(element => (uint)element.Count).ToArray();

            var bufferCount = (uint)sizes.Length;

            if (bufferCount == 0)
            {
                return(null);
            }

            // pin the IOperationData buffers
            var pinnedBuffers = this.originalMessage.Select(element => this.pinCollection.AddBlittable(element.Array)).ToArray();

            NativeRuntime.IFabricOperationData messageData = null;

            using (PinBlittable pinSizes = new PinBlittable(sizes), pinBuffers = new PinBlittable(pinnedBuffers))
            {
                messageData = messageDataFactory.CreateMessageData(
                    bufferCount,
                    pinSizes.AddrOfPinnedObject(),
                    pinBuffers.AddrOfPinnedObject());
            }

            this.savedNativeMessageRef = messageData;

            return(messageData);
        }
Esempio n. 6
0
 private IOperationData GetData()
 {
     NativeRuntime.IFabricOperationData nativeOperationData = this.nativeOperation as NativeRuntime.IFabricOperationData;
     return(new ReadOnlyOperationData(nativeOperationData));
 }
Esempio n. 7
0
        internal ReadOnlyOperationData(NativeRuntime.IFabricOperationData operationData)
        {
            Requires.Argument("operationData", operationData).NotNull();

            this.nativeOperationData = operationData;
        }
 private OperationData GetNextEndWrapper(NativeCommon.IFabricAsyncOperationContext context)
 {
     NativeRuntime.IFabricOperationData comData = this.enumerator.EndGetNext(context);
     return(comData == null ? null : OperationData.CreateFromNative(comData));
 }
 public virtual NativeCommon.IFabricAsyncOperationContext BeginReplicate(NativeRuntime.IFabricOperationData operationData, NativeCommon.IFabricAsyncOperationCallback callback, out long sequenceNumber)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
 public override NativeCommon.IFabricAsyncOperationContext BeginReplicate(NativeRuntime.IFabricOperationData operationData, NativeCommon.IFabricAsyncOperationCallback callback, out Int64 sequenceNumber)
 {
     ValidateStateLocks();
     return(base.BeginReplicate(operationData, callback, out sequenceNumber));
 }
Esempio n. 11
0
 private IOperationData GetNextEndWrapper(NativeCommon.IFabricAsyncOperationContext context)
 {
     NativeRuntime.IFabricOperationData comData = this.enumerator.EndGetNext(context);
     return(comData == null ? null : new ReadOnlyOperationData(comData));
 }