mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

Can't write data if in_callback == true and mosq->threaded == mosq_ts_none

Open wbl-dev opened this issue 9 years ago • 2 comments

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

wbl-dev avatar May 08 '17 08:05 wbl-dev

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.

ralight avatar May 08 '17 09:05 ralight

Got it!
Thanks for your help :)

wbl-dev avatar May 09 '17 02:05 wbl-dev