rendered paste bodybool BufferedSocket::threadSendFile() { dcassert(file != NULL); dcassert(inbufSize >= SMALL_BUFFER_SIZE); UploadManager *um = UploadManager::getInstance(); size_t sendMaximum, start = 0, current= 0; bool throttling; try { for(;;) { throttling = BOOLSETTING(THROTTLE_ENABLE); if (throttling) { start = TimerManager::getTick(); } { Lock l(cs); if(!tasks.empty()) return false; } size_t s; if (throttling) { sendMaximum = um->throttleGetSlice(); if (sendMaximum < 0) { throttling = false; sendMaximum = inbufSize; } s = (u_int32_t)min((int64_t)inbufSize, (int64_t)sendMaximum); } else { s = (BOOLSETTING(SMALL_SEND_BUFFER) ? SMALL_BUFFER_SIZE : inbufSize); } size_t actual = file->read(inbuf, s); if(actual > 0) { threadWrite((char*)inbuf, actual); fire(BufferedSocketListener::BytesSent(), s, actual); if (throttling) { int32_t cycle_time = um->throttleCycleTime(); current = TimerManager::getTick(); int32_t sleep_time = cycle_time - (current - start); if (sleep_time > 0 && sleep_time <= cycle_time) { Thread::sleep(sleep_time); } } } else { fire(BufferedSocketListener::TransmitDone()); return true; } } } catch(const Exception& e) { fail(e.getError()); return true; }}