예제 #1
0
파일: Flute.cs 프로젝트: pinguallyj/Pulse
            public override int Read(byte[] buffer, int offset, int count)
            {
                if (Interlocked.Read(ref _disposed) == 1)
                {
                    throw new ObjectDisposedException("Поток был освобождён.");
                }

                if (count == 0)
                {
                    return(0);
                }

                int timeout      = 10;
                int readableSize = 0;

                for (int i = 0; i < 100; i++)
                {
                    readableSize = Math.Min(count, _flute.GetReadableSize(_input.PointerOffset + Position));
                    if (readableSize == -1)
                    {
                        return(0);
                    }
                    if (readableSize > 0)
                    {
                        break;
                    }

                    Thread.Sleep(timeout); // Максимум 10 * 50(50+1)/2 = 50 сек 500 мсек
                    timeout += 10;
                }

                return(_input.Read(buffer, offset, readableSize));
            }