/* */ #include "RequestSlot.h" #include "Util.h" namespace aria2 { RequestSlot RequestSlot::nullSlot(0, 0, 0, 0); RequestSlot::RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex) :index(index), begin(begin), length(length), blockIndex(blockIndex) {} RequestSlot::RequestSlot(const RequestSlot& requestSlot) { copy(requestSlot); } void RequestSlot::copy(const RequestSlot& requestSlot) { index = requestSlot.index; begin = requestSlot.begin; length = requestSlot.length; blockIndex = requestSlot.blockIndex; dispatchedTime = requestSlot.dispatchedTime; } RequestSlot& RequestSlot::operator=(const RequestSlot& requestSlot) { if(this != &requestSlot) { copy(requestSlot); } return *this; } bool RequestSlot::operator==(const RequestSlot& requestSlot) const { return index == requestSlot.index && begin == requestSlot.begin; } bool RequestSlot::operator!=(const RequestSlot& requestSlot) const { return !(*this == requestSlot); } bool RequestSlot::operator<(const RequestSlot& requestSlot) const { if(index == requestSlot.index) { return begin < requestSlot.begin; } else { return index < requestSlot.index; } } void RequestSlot::setDispatchedTime() { dispatchedTime.reset(); } void RequestSlot::setDispatchedTime(time_t secFromEpoch) { dispatchedTime.setTimeInSec(secFromEpoch); } bool RequestSlot::isTimeout(time_t timeoutSec) const { return dispatchedTime.elapsed(timeoutSec); } unsigned int RequestSlot::getLatencyInMillis() const { return dispatchedTime.differenceInMillis(); } bool RequestSlot::isNull(const RequestSlot& requestSlot) { return requestSlot.index == 0 && requestSlot.begin == 0&& requestSlot.length == 0; } } // namespace aria2