Преглед на файлове

fix: netdrv_ch390在数据量很大的时候有内存泄漏,修正之

Wendal Chen преди 1 година
родител
ревизия
5b25463d03

+ 1 - 1
components/network/adapter_lwip2/net_lwip2.c

@@ -1027,7 +1027,7 @@ static void net_lwip2_create_socket_now(uint8_t adapter_index, uint8_t socket_id
 				adapter_index == NW_ADAPTER_INDEX_LWIP_WIFI_AP ||
 				adapter_index == NW_ADAPTER_INDEX_LWIP_ETH) {
 				prvlwip.socket[socket_id].pcb.tcp->keep_intvl = 5*1000;
-				prvlwip.socket[socket_id].pcb.tcp->keep_idle = 5*60*1000;
+				prvlwip.socket[socket_id].pcb.tcp->keep_idle = 45*1000;
 				prvlwip.socket[socket_id].pcb.tcp->keep_cnt = 2;
 			}
 			#endif

+ 0 - 1
components/network/netdrv/binding/luat_lib_netdrv.c

@@ -94,7 +94,6 @@ static int l_netdrv_mac(lua_State *L) {
     char buff[6] = {0};
     char tmpbuff[13] = {0};
     size_t len = 0;
-    int ret = 0;
     if (lua_isstring(L, 2)) {
         const char* tmp = luaL_checklstring(L, 2, &len);
         if (len != 6) {

+ 13 - 1
components/network/netdrv/include/luat_netdrv.h

@@ -38,6 +38,18 @@ typedef struct luat_netdrv_conf
     uint8_t irqpin;
 }luat_netdrv_conf_t;
 
+typedef struct luat_netdrv_statics_item
+{
+    uint64_t counter;
+    uint64_t bytes;
+}luat_netdrv_statics_item_t;
+
+typedef struct luat_netdrv_statics
+{
+    luat_netdrv_statics_item_t in;
+    luat_netdrv_statics_item_t out;
+    luat_netdrv_statics_item_t drop;
+}luat_netdrv_statics_t;
 
 luat_netdrv_t* luat_netdrv_setup(luat_netdrv_conf_t *conf);
 
@@ -47,6 +59,6 @@ int luat_netdrv_ready(int32_t id);
 
 int luat_netdrv_register(int32_t id, luat_netdrv_t* drv);
 
-int luat_netdrv_mac(int32_t id, char* new, char* old);
+int luat_netdrv_mac(int32_t id, const char* new, char* old);
 
 #endif

+ 1 - 0
components/network/netdrv/include/luat_netdrv_ch390h.h

@@ -19,6 +19,7 @@ typedef struct ch390h
     uint8_t hwaddr[6];
     struct netif* netif;
     ulwip_ctx_t ulwip;
+    luat_netdrv_statics_t statics;
     uint8_t rxbuff[1600];
     uint8_t txbuff[1600];
     struct pbuf* txqueue[CH390H_MAX_TX_NUM];

+ 9 - 8
components/network/netdrv/src/ch390h_task.c

@@ -60,12 +60,8 @@ static int ch390h_bootup(ch390h_t* ch) {
 static err_t netif_output(struct netif *netif, struct pbuf *p) {
     // LLOGD("lwip待发送数据 %p %d", p, p->tot_len);
     ch390h_t* ch = NULL;
-    struct pbuf *p2 = pbuf_alloc(PBUF_TRANSPORT, p->tot_len, PBUF_RAM);
-    if (p2 == NULL) {
-        LLOGE("内存不足, 无法传递pbuf");
-        return 0;
-    }
-    pbuf_copy(p2, p);
+    struct pbuf *p2 = NULL;
+
     for (size_t i = 0; i < MAX_CH390H_NUM; i++)
     {
         ch = ch390h_drvs[i];
@@ -78,7 +74,13 @@ static err_t netif_output(struct netif *netif, struct pbuf *p) {
         for (size_t j = 0; j < CH390H_MAX_TX_NUM; j++)
         {
             if (ch->txqueue[j] == NULL) {
-                // TODO 改成消息传送, 或者
+                p2 = pbuf_alloc(PBUF_TRANSPORT, p->tot_len, PBUF_RAM);
+                if (p2 == NULL) {
+                    LLOGE("内存不足, 无法传递pbuf");
+                    return 0;
+                }
+                pbuf_copy(p2, p);
+                // TODO 改成消息传送
                 ch->txqueue[j] = p2;
                 // LLOGD("找到空位了 %d", j);
                 if (is_waiting) {
@@ -88,7 +90,6 @@ static err_t netif_output(struct netif *netif, struct pbuf *p) {
             }
         }
     }
-    
     return 0;
 }
 

+ 1 - 1
components/network/netdrv/src/luat_netdrv.c

@@ -57,7 +57,7 @@ int luat_netdrv_register(int32_t id, luat_netdrv_t* drv) {
     return 0;
 }
 
-int luat_netdrv_mac(int32_t id, char* new, char* old) {
+int luat_netdrv_mac(int32_t id, const char* new, char* old) {
     if (id < 0 || id >= NW_ADAPTER_QTY) {
         return -1;
     }