Exemple #1
0
 public DiskWriteEntry(Torrent torrent, long torrentOffset, byte[] data, DiskWriteCallback callback)
 {
     this.torrent       = torrent;
     this.torrentOffset = torrentOffset;
     this.data          = data;
     this.callback      = callback;
 }
Exemple #2
0
        /// <summary>
        /// Queues a write to a specific torrent at an offset.
        /// </summary>
        /// <param name="torrent">The torrent to write to.</param>
        /// <param name="torrentOffset">The offset within the torrent.</param>
        /// <param name="data">The data of bytes to write.</param>
        /// <param name="callback">The callback with the result.</param>
        public static void QueueWrite(Torrent torrent, long torrentOffset, byte[] data, DiskWriteCallback callback = null)
        {
            if (torrent == null)
            {
                throw new ArgumentNullException("torrent");
            }
            else if (torrentOffset < 0L)
            {
                throw new ArgumentOutOfRangeException("torrentOffset");
            }
            else if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (data.Length == 0)
            {
                if (callback != null)
                {
                    callback.Invoke(true, null);
                }
                return;
            }

            var newEntry = new DiskWriteEntry(torrent, torrentOffset, data, callback);

            queuedWrites.Enqueue(newEntry);
            writeResetEvent.Set();
        }