public void PutCloseHandler(Object o, EventArgs args) {
Channel queue = (Channel) o;
// Get our mapping
AsDhtPutState adps = (AsDhtPutState) _adps_table[queue];
if(adps == null) {
return;
}
lock(_adps_table.SyncRoot) {
_adps_table.Remove(queue);
}
/* Check out results from our request and update the overall results
* send a message to our client if we're done!
*/
bool result = false;
try {
RpcResult rpcResult = (RpcResult) queue.Dequeue();
result = (bool) rpcResult.Result;
}
catch (Exception) {}
if(result) {
// Once we get pcount to a majority, we ship off the result
if(Interlocked.Increment(ref adps.pcount) == MAJORITY) {
adps.returns.Enqueue(true);
adps.returns.Close();
}
}
else {
// Once we get to ncount to 1 less than a majority, we ship off the
// result, because we can't get pcount equal to majority any more!
if(Interlocked.Increment(ref adps.ncount) == MAJORITY - 1 || 1 == DEGREE) {
adps.returns.Enqueue(new DhtPutException(DEGREE, adps.pcount, adps.ncount));
adps.returns.Close();
}
}
}