Ejemplo n.º 1
0
        private void GetNewSegment()
        {
            _currentInputSegment = _incommingSegments.GetResult();
            if (_currentInputSegment == null)
            {
                _readtcs.SetResult(0);
                return;
            }

            _bytesReadInCurrentSegment = 0;
            _currentContentLength      = _currentInputSegment.CurrentContentLength;

            if (_currentContentLength == 0)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
                _readtcs.SetResult(0);
                return;
            }
            else
            {
                _socket.ReciveInternal();
                CompleteRead();
            }
        }
Ejemplo n.º 2
0
        public void Flush(bool moreData)
        {
            if (_remainingSpaceInOutputSegment == 0)
            {
                _socket.CommitSend();
            }
            else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
            {
                return;
            }
            else
            {
                unsafe
                {
                    _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
                }
                _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE);

                if (moreData)
                {
                    _currentOutputSegment          = _socket.SendBufferPool.GetBuffer();
                    _outputSegmentTotalLength      = _currentOutputSegment.TotalLength;
                    _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
                }
                else
                {
                    _remainingSpaceInOutputSegment = 0;
                    _outputSegmentTotalLength      = 0;
                }
            }
        }
Ejemplo n.º 3
0
        public void Flush(bool moreData)
        {
            if (_remainingSpaceInOutputSegment == 0)
                _socket.CommitSend();
            else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength)
                return;
            else
            {
                unsafe
                {
                    _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment;
                }
                _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE);

                if (moreData)
                {
                    _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
                    _outputSegmentTotalLength = _currentOutputSegment.TotalLength;
                    _remainingSpaceInOutputSegment = _outputSegmentTotalLength;
                }
                else
                {
                    _remainingSpaceInOutputSegment = 0;
                    _outputSegmentTotalLength = 0;
                }

            }
        }
Ejemplo n.º 4
0
        public RioBufferSegment GetResult()
        {
            var res = _currentValue;

            _currentValue = null;
            return(res);
        }
Ejemplo n.º 5
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 6
0
        private void CompleteRead()
        {
            var toCopy = _currentContentLength - _bytesReadInCurrentSegment;

            if (toCopy > _readCount)
            {
                toCopy = _readCount;
            }

            unsafe
            {
                fixed(byte *p = &_readBuffer[_readoffset])
                System.Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy);
            }

            _bytesReadInCurrentSegment += toCopy;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
            }

            _readtcs.SetResult(toCopy);
        }
Ejemplo n.º 7
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
             WinSock.ThrowLastWSAError();
     }
 }
Ejemplo n.º 8
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment = null;
     _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
Ejemplo n.º 9
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
     {
         _continuation();
     }
 }
Ejemplo n.º 10
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment      = null;
     _currentOutputSegment     = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate    = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
Ejemplo n.º 11
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
         {
             WinSock.ThrowLastWSAError();
         }
     }
 }
Ejemplo n.º 12
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments = new RioBufferSegment[segmentCount];
            TotalLength = segmentCount * segmentLength;
            BufferPointer = Marshal.AllocHGlobal(TotalLength);
            _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf<RIO_BUFSEGMENT>() * segmentCount);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength);
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 13
0
        public RioFixedBufferPool(int segmentCount, int segmentLength)
        {
            AllSegments     = new RioBufferSegment[segmentCount];
            TotalLength     = segmentCount * segmentLength;
            BufferPointer   = Marshal.AllocHGlobal(TotalLength);
            _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf <RIO_BUFSEGMENT>() * segmentCount);

            for (int i = 0; i < segmentCount; i++)
            {
                var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength);
                AllSegments[i] = b;
                _availableSegments.Enqueue(b);
            }
        }
Ejemplo n.º 14
0
        public void Set(RioBufferSegment item)
        {
            bool taken = false;
            _spinLock.Enter(ref taken);
            //if (!taken)
            //    throw new ArgumentException("fuu");

            //if (_currentValue != null)
            //    throw new ArgumentException("fuu");

            _currentValue = item;
            _spinLock.Exit();

            if (_continuation != null)
                ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, null);
        }
Ejemplo n.º 15
0
        public void Set(RioBufferSegment item)
        {
            bool taken = false;

            _spinLock.Enter(ref taken);
            //if (!taken)
            //    throw new ArgumentException("fuu");

            //if (_currentValue != null)
            //    throw new ArgumentException("fuu");

            _currentValue = item;
            _spinLock.Exit();

            if (_continuation != null)
            {
                ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, null);
            }
        }
Ejemplo n.º 16
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
         WinSock.ThrowLastWSAError();
 }
Ejemplo n.º 17
0
 public void ReleaseBuffer(RioBufferSegment bufferIndex)
 {
     _availableSegments.Enqueue(bufferIndex);
 }
Ejemplo n.º 18
0
 public void ReleaseBuffer(RioBufferSegment bufferIndex)
 {
     _availableSegments.Enqueue(bufferIndex);
 }
Ejemplo n.º 19
0
 public bool TryGetBuffer(out RioBufferSegment buf)
 {
     return(_availableSegments.TryDequeue(out buf));
 }
Ejemplo n.º 20
0
        private void CompleteRead()
        {
            var toCopy = _currentContentLength - _bytesReadInCurrentSegment;
            if (toCopy > _readCount)
                toCopy = _readCount;

            unsafe
            {
                fixed (byte* p = &_readBuffer[_readoffset])
                    System.Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy);
            }

            _bytesReadInCurrentSegment += toCopy;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
            }

            _readtcs.SetResult(toCopy);
        }
Ejemplo n.º 21
0
        private void GetNewSegment()
        {
            _currentInputSegment = _incommingSegments.GetResult();
            if (_currentInputSegment == null)
            {
                _readtcs.SetResult(0);
                return;
            }

            _bytesReadInCurrentSegment = 0;
            _currentContentLength = _currentInputSegment.CurrentContentLength;

            if (_currentContentLength == 0)
            {
                _currentInputSegment.Dispose();
                _currentInputSegment = null;
                _readtcs.SetResult(0);
                return;
            }
            else
            {
                _socket.ReciveInternal();
                CompleteRead();
            }
        }
Ejemplo n.º 22
0
 public RioBufferSegment GetResult()
 {
     var res = _currentValue;
     _currentValue = null;
     return res;
 }
Ejemplo n.º 23
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
         _continuation();
 }
Ejemplo n.º 24
0
 public bool TryGetBuffer(out RioBufferSegment buf)
 {
     return _availableSegments.TryDequeue(out buf);
 }