Beispiel #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();
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #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;
                }

            }
        }
        public RioBufferSegment GetResult()
        {
            var res = _currentValue;

            _currentValue = null;
            return(res);
        }
Beispiel #5
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
     {
         WinSock.ThrowLastWSAError();
     }
 }
Beispiel #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);
        }
Beispiel #7
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
             WinSock.ThrowLastWSAError();
     }
 }
Beispiel #8
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment = null;
     _currentOutputSegment = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
     {
         _continuation();
     }
 }
Beispiel #10
0
 public RioStream(RioConnectionOrientedSocket socket)
 {
     _socket = socket;
     _currentInputSegment      = null;
     _currentOutputSegment     = _socket.SendBufferPool.GetBuffer();
     _getNewSegmentDelegate    = GetNewSegment;
     socket.OnIncommingSegment = s => _incommingSegments.Set(s);
     socket.ReciveInternal();
 }
Beispiel #11
0
 public void WritePreAllocated(RioBufferSegment Segment)
 {
     unsafe
     {
         if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index))
         {
             WinSock.ThrowLastWSAError();
         }
     }
 }
Beispiel #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);
            }
        }
        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);
            }
        }
Beispiel #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);
        }
        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);
            }
        }
Beispiel #16
0
 internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags)
 {
     if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index))
         WinSock.ThrowLastWSAError();
 }
Beispiel #17
0
 public void ReleaseBuffer(RioBufferSegment bufferIndex)
 {
     _availableSegments.Enqueue(bufferIndex);
 }
 public void ReleaseBuffer(RioBufferSegment bufferIndex)
 {
     _availableSegments.Enqueue(bufferIndex);
 }
 public bool TryGetBuffer(out RioBufferSegment buf)
 {
     return(_availableSegments.TryDequeue(out buf));
 }
Beispiel #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);
        }
Beispiel #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();
            }
        }
Beispiel #22
0
 public RioBufferSegment GetResult()
 {
     var res = _currentValue;
     _currentValue = null;
     return res;
 }
Beispiel #23
0
 public void Dispose()
 {
     _currentValue?.Dispose();
     _currentValue = null;
     if (_continuation != null)
         _continuation();
 }
Beispiel #24
0
 public bool TryGetBuffer(out RioBufferSegment buf)
 {
     return _availableSegments.TryDequeue(out buf);
 }