服务器如何调试mqtt协议,新人入坑,mqtt调试

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;

}