Unlocks send_queue_lock before calling callbacks in case send_from_queue is invoked in callbacks
This commit is contained in:
parent
514a135e0c
commit
9ca86827d9
1 changed files with 12 additions and 4 deletions
|
|
@ -77,22 +77,30 @@ namespace SimpleWeb {
|
||||||
auto lock = self->session->connection->handler_runner->continue_lock();
|
auto lock = self->session->connection->handler_runner->continue_lock();
|
||||||
if(!lock)
|
if(!lock)
|
||||||
return;
|
return;
|
||||||
std::lock_guard<std::mutex> send_queue_lock(self->send_queue_mutex);
|
std::unique_lock<std::mutex> send_queue_lock(self->send_queue_mutex);
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
auto it = self->send_queue.begin();
|
auto it = self->send_queue.begin();
|
||||||
if(it->second)
|
auto callback = std::move(it->second);
|
||||||
it->second(ec);
|
|
||||||
self->send_queue.erase(it);
|
self->send_queue.erase(it);
|
||||||
if(self->send_queue.size() > 0)
|
if(self->send_queue.size() > 0)
|
||||||
self->send_from_queue();
|
self->send_from_queue();
|
||||||
|
|
||||||
|
send_queue_lock.unlock();
|
||||||
|
if(callback)
|
||||||
|
callback(ec);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// All handlers in the queue is called with ec:
|
// All handlers in the queue is called with ec:
|
||||||
|
std::vector<std::function<void(const error_code &)>> callbacks;
|
||||||
for(auto &pair : self->send_queue) {
|
for(auto &pair : self->send_queue) {
|
||||||
if(pair.second)
|
if(pair.second)
|
||||||
pair.second(ec);
|
callbacks.emplace_back(std::move(pair.second));
|
||||||
}
|
}
|
||||||
self->send_queue.clear();
|
self->send_queue.clear();
|
||||||
|
|
||||||
|
send_queue_lock.unlock();
|
||||||
|
for(auto &callback : callbacks)
|
||||||
|
callback(ec);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue