mirror of
https://github.com/eclipse/paho.mqtt.cpp.git
synced 2025-05-09 19:31:22 +08:00
Merge pull request #519 from sandro97git/set-callback-fix-potential-deadlock
Fix potential deadlock in set_callback
This commit is contained in:
commit
461f765430
@ -315,9 +315,10 @@ void async_client::remove_token(token* tok)
|
|||||||
|
|
||||||
void async_client::set_callback(callback& cb)
|
void async_client::set_callback(callback& cb)
|
||||||
{
|
{
|
||||||
guard g(lock_);
|
{
|
||||||
userCallback_ = &cb;
|
guard g(lock_);
|
||||||
|
userCallback_ = &cb;
|
||||||
|
}
|
||||||
int rc = MQTTAsync_setConnected(cli_, this, &async_client::on_connected);
|
int rc = MQTTAsync_setConnected(cli_, this, &async_client::on_connected);
|
||||||
|
|
||||||
if (rc == MQTTASYNC_SUCCESS) {
|
if (rc == MQTTASYNC_SUCCESS) {
|
||||||
@ -330,6 +331,7 @@ void async_client::set_callback(callback& cb)
|
|||||||
MQTTAsync_setConnected(cli_, nullptr, nullptr);
|
MQTTAsync_setConnected(cli_, nullptr, nullptr);
|
||||||
|
|
||||||
if (rc != MQTTASYNC_SUCCESS) {
|
if (rc != MQTTASYNC_SUCCESS) {
|
||||||
|
guard g(lock_);
|
||||||
userCallback_ = nullptr;
|
userCallback_ = nullptr;
|
||||||
throw exception(rc);
|
throw exception(rc);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user