Comments (5)
提供了动态设置write内存的API接口 mqtt_set_write_buf_size()
,调用即可,相关代码实现可以看代码
from mqttclient.
感谢,之前有使用 mqtt_set_write_buf_size() 尝试过,没生效,
刚按您说的看了一下代码,在mqttclient.c - mqtt_init()里面有段注释/*only malloc write buf and read buf when call mqtt_init function /
我现在按以下3步骤来做可以实现
platform_memory_free(client->mqtt_write_buf); //释放之前的
mqtt_set_write_buf_size(client, size); //配置需要的
client->mqtt_write_buf = (uint8_t) platform_memory_alloc(client->mqtt_write_buf_size); //申请内存
不知道这样写是否可以?
另外在您那个在线代码生成里面 mqtt_set_write_buf_size() 也是在 调用mqtt_init()之后的 我一开始是参考的那个一直没成功是不是也是这个原因呢,请指正谢谢!
from mqttclient.
你看我最新的代码,可以切换到stable分支,可以动态去调整的,即使你知道怎么去申请、释放client内部的内存,但也请不要在外部操作,因为它是由client内部维护的。
static uint32_t mqtt_write_buf_malloc(mqtt_client_t* c, uint32_t size)
{
MQTT_ROBUSTNESS_CHECK(c, 0);
if (NULL != c->mqtt_write_buf)
platform_memory_free(c->mqtt_write_buf);
c->mqtt_write_buf_size = size;
/* limit the size of the read buffer */
if ((MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_write_buf_size) || (MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_write_buf_size))
c->mqtt_write_buf_size = MQTT_DEFAULT_BUF_SIZE;
c->mqtt_write_buf = (uint8_t*) platform_memory_alloc(c->mqtt_write_buf_size);
if (NULL == c->mqtt_write_buf) {
MQTT_LOG_E("%s:%d %s()... malloc write buf failed...", __FILE__, __LINE__, __FUNCTION__);
RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
}
return c->mqtt_write_buf_size;
}
uint32_t mqtt_set_write_buf_size(mqtt_client_t *c, uint32_t size)
{
return mqtt_write_buf_malloc(c, size);
}
from mqttclient.
好的,已经更新,
另外想请教一下,我把缓存已经设置足够的情况下,我的数据包一但超出 1MB ,就发送不成功,
调试发现板子貌似断网了,mqtt一直在重连,就一直卡着,ping板子也ping不通了
怀疑是有什么地方有1MB限制,然后超出了,内存溢出把网络搞挂了,
我找了lwip的配置,也尝试放大但都没有作用,请问还有哪边可以配置呢?
谢谢!
from mqttclient.
关于lwip的底层这个,你得排查一下了,可能是lwip本身限制了内存相关的问题(导致协议栈本身无法申请那么大的内存,也就没办法给你发出去),也可能是驱动的问题(发着发着数据驱动挂了,lwip也不能工作了)
from mqttclient.
Related Issues (20)
- 如何配置 TLS/SSL 以实现仅服务器加密而不进行服务器认证的方式,有实现案例嘛?
- 执行完./build.sh后,在./build/bin目录下没有emqx等执行文件 HOT 1
- 最新源码编译时mqttclient-master/common/log/salof_config.h:12:10: fatal error: mqtt_config.h: No such file or directory HOT 1
- 执行build.sh出现问题 HOT 3
- mqttclient连接上server后,断开网络, mqttclient会尝试重连,每次重连就会出现内存泄漏 HOT 6
- v1.2.0版本和master版本为何删除了test目录?目前执行make-libmqttclient.sh编译会失败 HOT 1
- 怎样增加windows的支持
- 目前有没有1.2.0版本的rt-thread。或者该分支支持rt-thread平台运行吗?
- 请问一下linux下还支持x509证书吗
- tls验证openssl CA证书失败 HOT 3
- ../mqttclient/mqttclient.c:951 mqtt_yield_thread()..., mqtt reconnect timeout....不自动重连的问题
- linux下,mqtt服务器一关闭程序就退出了?
- cleansession=false,无法接受离线消息
- cleansession=false,无法接受离线消息 HOT 1
- 怎么调用mqtt_subscribe使用同一个连接订阅多个主题,应该怎么调整相关代码,调整代码的思路是什么
- 自签名双向认证如何实现? HOT 1
- mqtt5.0
- mqtt_subscribe 缓存已经改成8192, 最大接受数据971个
- platform_net_socket_recv_timeout 区分超时与连接断开
- 枚举变量非对齐访问问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttclient.