public DiskReadEntry(Torrent torrent, long torrentOffset, byte[] buffer, int bufferOffset, int readLength, DiskReadCallback callback) { this.torrent = torrent; this.torrentOffset = torrentOffset; this.buffer = buffer; this.bufferOffset = bufferOffset; this.readLength = readLength; this.callback = callback; }
/// <summary> /// Queues a read from a specific torrent at an offset. /// </summary> /// <param name="torrent">The torrent to read from.</param> /// <param name="torrentOffset">The offset within the torrent.</param> /// <param name="buffer">The buffer to read into.</param> /// <param name="bufferOffset">The offset within the buffer to start writing into.</param> /// <param name="readLength">The length of bytes to read.</param> /// <param name="callback">The callback with the result.</param> public static void QueueRead(Torrent torrent, long torrentOffset, byte[] buffer, int bufferOffset, int readLength, DiskReadCallback callback) { if (torrent == null) { throw new ArgumentNullException("torrent"); } else if (torrentOffset < 0L) { throw new ArgumentOutOfRangeException("torrentOffset"); } else if (buffer == null) { throw new ArgumentNullException("buffer"); } else if (bufferOffset < 0 || bufferOffset >= buffer.Length) { throw new ArgumentOutOfRangeException("bufferOffset"); } else if (readLength < 0 || (bufferOffset + readLength) > buffer.Length) { throw new ArgumentOutOfRangeException("readLength"); } else if (callback == null) { throw new ArgumentNullException("callback"); } if (readLength == 0) { callback.Invoke(true, null, 0); return; } var newEntry = new DiskReadEntry(torrent, torrentOffset, buffer, bufferOffset, readLength, callback); queuedReads.Enqueue(newEntry); readResetEvent.Set(); }