size_t UploadManager::throttleGetSlice() { if (mThrottleEnable) { size_t left = mUploadLimit - mBytesSpokenFor; if (left > 0) { if (left > 2*mByteSlice) { mBytesSpokenFor += mByteSlice; return mByteSlice; } else { mBytesSpokenFor += left; return left; } } else { return 16; // must send > 0 bytes or threadSendFile thinks the transfer is complete } } else { return (size_t)-1; } } size_t UploadManager::throttleCycleTime() { if (mThrottleEnable) return mCycleTime; return 0; } void UploadManager::throttleZeroCounters() { if (mThrottleEnable) { mBytesSpokenFor = 0; mBytesSent = 0; } } void UploadManager::throttleBytesTransferred(u_int32_t i) { mBytesSent += i; } void UploadManager::throttleSetup() { unsigned int num_transfers = uploads.size(); mUploadLimit = (SETTING(MAX_UPLOAD_SPEED_LIMIT) * 1024); mThrottleEnable = BOOLSETTING(THROTTLE_ENABLE) && (mUploadLimit > 0) && (num_transfers > 0); if (mThrottleEnable) { if (mUploadLimit <= (INBUFSIZE * 10 * num_transfers)) { mByteSlice = mUploadLimit / (5 * num_transfers); if (mByteSlice > INBUFSIZE) mByteSlice = INBUFSIZE; mCycleTime = 1000 / 10; } else { mByteSlice = INBUFSIZE; mCycleTime = 1000 * INBUFSIZE / mUploadLimit; } } } UploadQueueItem::UserMap UploadManager::getQueue() { Lock l(cs); return UploadQueueItems; }