Esempio n. 1
0
        public int Read(byte[] buffer, int offset, int count, bool fillBuffer = false /*, ReadingGate fromGate = null*/)
        {
#if DEBUG
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "must be greater or equal to 0");
            }
            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException("count", "must be greater than 0");
            }
#endif

            int totalRead = 0;

            while (totalRead < count)
            {
                int available;
                int readPos = this.InternalGetReadyToReadEntries(count - totalRead, out available /*, fromGate*/);

                if (_state._resetApplied)
                {
                    throw new Exception("Can't be read since the buffer is in Reset state");
                    // break;
                }

                if (available == 0)
                {
                    if (fillBuffer)
                    {
                        FillUpBufferFromSocket();
                        // _writeLock.WaitOne();
                        continue;
                    }
                    break;
                }

                int dstOffset = offset + totalRead;

                BufferUtil.FastCopy(buffer, dstOffset, _buffer, readPos + _bufferPadding, available);


                totalRead += available;

//				if (fromGate != null)
//				{
//					lock (fromGate)
//					{
//						fromGate.gpos += (uint)available;
//						fromGate.length -= (uint)available;
//					}
//				}
//				else
                {
                    // if (!fillBuffer) break;
                    var newReadPos = _state._readPosition + (uint)available;
                    _state._readPosition     = newReadPos;                 // volative write
                    _state._readPositionCopy = newReadPos;
                }

                _readLock.Set();                 // signal - if someone is waiting
            }

            return(totalRead);
        }
Esempio n. 2
0
 public void FastBufferCopy()
 {
     BufferUtil.FastCopy(_dest, 0, _src, 0, BufferSizeToCopy);
 }