新人入坑,mqtt调试

源码:https://github.com/eclipse/paho.mqtt.c.git

1. 迁移代码时,遇到代码编译不通过,处理,针对源码中的编译规则,删除makefile文件,修改makefilelist文件,重新执行cmake ./

2. 使用mqtt协议传输音视频,经历过内存泄漏问题

一般gdb调试显示调用在mqtt库中,但是需要的地方依旧在上层对mqtt send的调用调度和回调函数的管理上

3. cpu loading过大的问题。

检查mqtt代码,发现线程等待有问题,这块代码在针对mips平台差异上编译有点异常,导致线程等待失效

4. 现在遇到一个bus error:

[1]+  Bus error (core dumped)    ./mqtt-test

有遇到过吗?分析core文件,定位到函数调用:MQTTAsync_processCommand

仅在线程MQTTAsync_sendThread中调用,

其实这个问题解决点还是在上层调用。针对这个问题还发邮件给到过github上源码的贡献者,感谢Krzysztof Bogucki的解答释疑。

上层发送的消息,mqtt接收后会放入缓存中,如果网络波动,会导致系统可有内存吃紧,这块处理不合理就会出现bus error等类似错误,从而系统奔溃。

static thread_return_type WINAPI MQTTAsync_sendThread(void* n)
{
	FUNC_ENTRY;
	MQTTAsync_lock_mutex(mqttasync_mutex);
	sendThread_state = RUNNING;
	sendThread_id = Thread_getid();
	MQTTAsync_unlock_mutex(mqttasync_mutex);
	while (!tostop)
	{
		int rc;

		while (commands->count > 0)
		{
			if (MQTTAsync_processCommand() == 0)
				break;  /* no commands were processed, so go into a wait */
		}
#if !defined(WIN32) && !defined(WIN64)
		if ((rc = Thread_wait_cond(send_cond, 1)) != 0 && rc != ETIMEDOUT)
			Log(LOG_ERROR, -1, "Error %d waiting for condition variable", rc);
#else
		if ((rc = Thread_wait_sem(send_sem, 1000)) != 0 && rc != ETIMEDOUT)
			Log(LOG_ERROR, -1, "Error %d waiting for semaphore", rc);
#endif

		MQTTAsync_checkTimeouts();
	}
	sendThread_state = STOPPING;
	MQTTAsync_lock_mutex(mqttasync_mutex);
	sendThread_state = STOPPED;
	sendThread_id = 0;
	MQTTAsync_unlock_mutex(mqttasync_mutex);
	FUNC_EXIT;
	return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值