mosquitto
mosquitto copied to clipboard
Can't write data if in_callback == true and mosq->threaded == mosq_ts_none
I want to send a subscribe after connecting finished. So i write subscribe code in on_connect callback. But it has some problems.
in net_mosq.c
if(mosq->in_callback == false && mosq->threaded == mosq_ts_none){
return _mosquitto_packet_write(mosq);
}else{
return MOSQ_ERR_SUCCESS;
}
I remove mosq->in_callback == false && and it works. It makes me very confused. Would you mind tell me why we need mosq->in_callback == false.
Wish your help. Thanks
This is to prevent deadlocks when using the threaded interface.
It sounds to me as though the likely cause of your actual problem is that you aren't using one of mosquitto_loop_forever() or mosquitto_loop_start() - one of these is required to ensure that network traffic is processed.
Got it!
Thanks for your help :)