ReusableTask Tick(int delta, bool waitForBufferedIO) { UpdateTimer.Restart(); ReadMonitor.Tick(delta); WriteMonitor.Tick(delta); WriteLimiter.UpdateChunks(Settings.MaximumDiskWriteRate, WriteRate); ReadLimiter.UpdateChunks(Settings.MaximumDiskReadRate, ReadRate); var processTask = ProcessBufferedIOAsync(); return(waitForBufferedIO ? processTask : ReusableTask.CompletedTask); }
internal NativeLabelScanWriter(int batchSize, WriteMonitor monitor) { this._pendingUpdates = new NodeLabelUpdate[batchSize]; this._addMerger = (existingKey, newKey, existingValue, newValue) => { monitor.MergeAdd(existingValue, newValue); return(existingValue.add(newValue)); }; this._removeMerger = (existingKey, newKey, existingValue, newValue) => { monitor.MergeRemove(existingValue, newValue); return(existingValue.remove(newValue)); }; this._monitor = monitor; }
void Write(ITorrentData manager, long offset, byte [] buffer, int count) { WriteMonitor.AddDelta(count); if (offset < 0 || offset + count > manager.Size) { throw new ArgumentOutOfRangeException(nameof(offset)); } int i; int totalWritten = 0; var files = manager.Files; for (i = 0; i < files.Length; i++) { if (offset < files[i].Length) { break; } offset -= files[i].Length; } while (totalWritten < count) { int fileToWrite = (int)Math.Min(files[i].Length - offset, count - totalWritten); fileToWrite = Math.Min(fileToWrite, Piece.BlockSize); Writer.Write(files[i], offset, buffer, totalWritten, fileToWrite); offset += fileToWrite; totalWritten += fileToWrite; if (offset >= files[i].Length) { offset = 0; i++; } } }
ReusableTask WriteToFilesAsync(ITorrentData torrent, BlockInfo block, byte[] buffer) { WriteMonitor.AddDelta(block.RequestLength); return(Writer.WriteToFilesAsync(torrent, block, buffer)); }