MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / recv_with_timeout

Method recv_with_timeout

smallthinker/tools/server/server.cpp:1794–1817  ·  view source on GitHub ↗

same as recv(), but have timeout in seconds if timeout is reached, nullptr is returned

Source from the content-addressed store, hash-verified

1792 // same as recv(), but have timeout in seconds
1793 // if timeout is reached, nullptr is returned
1794 server_task_result_ptr recv_with_timeout(const std::unordered_set<int> & id_tasks, int timeout) {
1795 while (true) {
1796 std::unique_lock<std::mutex> lock(mutex_results);
1797
1798 for (int i = 0; i < (int) queue_results.size(); i++) {
1799 if (id_tasks.find(queue_results[i]->id) != id_tasks.end()) {
1800 server_task_result_ptr res = std::move(queue_results[i]);
1801 queue_results.erase(queue_results.begin() + i);
1802 return res;
1803 }
1804 }
1805
1806 std::cv_status cr_res = condition_results.wait_for(lock, std::chrono::seconds(timeout));
1807 if (!running) {
1808 SRV_DBG("%s : queue result stop\n", __func__);
1809 std::terminate(); // we cannot return here since the caller is HTTP code
1810 }
1811 if (cr_res == std::cv_status::timeout) {
1812 return nullptr;
1813 }
1814 }
1815
1816 // should never reach here
1817 }
1818
1819 // single-task version of recv()
1820 server_task_result_ptr recv(int id_task) {

Callers 2

receive_multi_resultsMethod · 0.80

Calls 4

findMethod · 0.80
sizeMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected