コード例 #1
0
        async Task <int> Read(byte[] buffer, int offset, int count, bool async, CancellationToken cancellationToken = default)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }
            if (buffer.Length - offset < count)
            {
                throw new ArgumentException("Invalid offset or count for this buffer");
            }

            CheckDisposed();

            var chunkCount = Math.Min(count, _manager.MaxTransferBlockSize);
            var read       = 0;

            while (read < count)
            {
                var bytesRead = await _manager.ExecuteFunctionGetBytes(
                    "loread", buffer, offset + read, count - read, async, cancellationToken, _fd, chunkCount);

                _pos += bytesRead;
                read += bytesRead;
                if (bytesRead < chunkCount)
                {
                    return(read);
                }
            }
            return(read);
        }
コード例 #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }
            if (buffer.Length - offset < count)
            {
                throw new ArgumentException("Invalid offset or count for this buffer");
            }
            Contract.EndContractBlock();

            CheckDisposed();

            int chunkCount = Math.Min(count, _manager.MaxTransferBlockSize);
            int read       = 0;

            while (read < count)
            {
                var bytesRead = _manager.ExecuteFunctionGetBytes("loread", buffer, offset + read, count - read, _fd, chunkCount);
                _pos += bytesRead;
                read += bytesRead;
                if (bytesRead < chunkCount)
                {
                    return(read);
                }
            }
            return(read);
        }