mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
dhtrunner: don't block networking thread during processing
This commit is contained in:
1 parent
7e346cfcb8
commit
4aebef5e51
1 file changed
+12
-9
+12
-9
@@ -167,18 +167,21 @@ DhtRunner::loop_()
|
||||
}
|
||||
|
||||
time_point wakeup {};
|
||||
decltype(rcv) received {};
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(sock_mtx);
|
||||
if (not rcv.empty()) {
|
||||
for (const auto& pck : rcv) {
|
||||
auto& buf = pck.first;
|
||||
auto& from = pck.second;
|
||||
wakeup = dht_->periodic(buf.data(), buf.size()-1, (sockaddr*)&from.first, from.second);
|
||||
}
|
||||
rcv.clear();
|
||||
} else {
|
||||
wakeup = dht_->periodic(nullptr, 0, nullptr, 0);
|
||||
// move to stack
|
||||
received = std::move(rcv);
|
||||
}
|
||||
if (not received.empty()) {
|
||||
for (const auto& pck : received) {
|
||||
auto& buf = pck.first;
|
||||
auto& from = pck.second;
|
||||
wakeup = dht_->periodic(buf.data(), buf.size()-1, (sockaddr*)&from.first, from.second);
|
||||
}
|
||||
received.clear();
|
||||
} else {
|
||||
wakeup = dht_->periodic(nullptr, 0, nullptr, 0);
|
||||
}
|
||||
|
||||
Dht::Status nstatus4 = dht_->getStatus(AF_INET);
|
||||
|
||||
Reference in new issue
Block a user