示例#1
0
        private bool TryEnqueue(IList <ArraySegment <byte> > items, out bool conflict)
        {
            conflict = false;
            int oldCurrent = mOffset;

            if (oldCurrent + items.Count >= QUEUE_SIZE)
            {
                return(false);
            }

            if (Interlocked.CompareExchange(ref mOffset, oldCurrent + items.Count, oldCurrent) != oldCurrent)
            {
                conflict = true;
                return(false);
            }

            for (int i = 0; i < items.Count; i++)
            {
                ArraySegment <byte> item = items[i];
                var gcHandle             = GCHandle.Alloc(item.Array, GCHandleType.Pinned);
                mPins[oldCurrent + i]        = gcHandle;
                this.mBuffer[oldCurrent + i] = UVIntrop.buf_init(gcHandle.AddrOfPinnedObject() + item.Offset, item.Count);
            }
            return(true);
        }
示例#2
0
        public unsafe void Write(byte[] datas, Int32 offset, Int32 count)
        {
            fixed(byte *p = datas)
            {
                UVIntrop.uv_buf_t[] mbuf = new UVIntrop.uv_buf_t[] {
                    UVIntrop.buf_init((IntPtr)(p + offset), count)
                };

                UVIntrop.try_write(this, mbuf, 1);
            }
        }
示例#3
0
        private unsafe bool TryEnqueue(ArraySegment <byte> item, out bool conflict)
        {
            conflict = false;
            int currentCount = mOffset;

            if (currentCount >= QUEUE_SIZE)
            {
                return(false);
            }

            if (Interlocked.CompareExchange(ref mOffset, currentCount + 1, currentCount) != currentCount)
            {
                conflict = true;
                return(false);
            }

            //添加
            var gcHandle = GCHandle.Alloc(item.Array, GCHandleType.Pinned);

            mPins[currentCount]        = gcHandle;
            this.mBuffer[currentCount] = UVIntrop.buf_init(gcHandle.AddrOfPinnedObject() + item.Offset, item.Count);

            return(true);
        }