/// <summary> /// Reads the specified read list. /// </summary> /// <param name="readList">The read list. The first tuple item specifies /// where in the result array to put the read result.</param> /// <param name="readResults">The read results.</param> /// <param name="tm">The tm.</param> /// <returns>The list of indices of failed items in the readlist.</returns> private List <int> Read(List <Tuple <int, long, int> > readList, byte[][] readResults, TorrentManager tm) { var failedItems = new List <int>(); for (int i = 0; i < readList.Count(); i++) { var tuple = readList[i]; AutoResetEvent waitHandle = new AutoResetEvent(false); int resultIndex = tuple.Item1; long offset = tuple.Item2; int count = tuple.Item3; byte[] buffer = new byte[count]; bool successful = false; _diskManager.QueueRead(tm, offset, buffer, count, delegate(bool succ) { // DiskManager with DedupDiskWriter reads data according to // mappings for deduplicated data. successful = succ; if (succ) { logger.DebugFormat("Read (offset, count) = ({0}, {1}) successful.", offset, count); readResults[resultIndex] = buffer; } else { failedItems.Add(i); } waitHandle.Set(); }); waitHandle.WaitOne(); waitHandle.Close(); } return(failedItems); }
public void ReadFail() { var called = false; _writer.read = true; Hookup(); _diskManager.QueueRead(_rig.Manager, 0, _data, _data.Length, delegate { called = true; }); CheckFail(); Assert.IsTrue(called, "#delegate called"); }