Просмотр исходного кода

fix: icmp,修正内存泄露,demo兼容wifi模组

Wendal Chen 9 месяцев назад
Родитель
Сommit
18e8527252
2 измененных файлов с 15 добавлено и 4 удалено
  1. 1 1
      components/network/icmp/src/luat_icmp.c
  2. 14 3
      demo/icmp/ping/main.lua

+ 1 - 1
components/network/icmp/src/luat_icmp.c

@@ -150,8 +150,8 @@ int luat_icmp_ping(luat_icmp_ctx_t* ctx, ip_addr_t* dst, size_t size) {
     // LLOGD("ICMP sendto %s --> %s", buff, buff2);
     ctx->send_time = luat_mcu_tick64_ms();
     ret = raw_sendto(ctx->pcb, p, dst);
+    pbuf_free(p);
     if (ret) {
-        pbuf_free(p);
         LLOGW("ICMP sendto error %d %s --> %s", ret, buff, buff2);
         return ret;
     }

+ 14 - 3
demo/icmp/ping/main.lua

@@ -10,13 +10,24 @@ sys.subscribe("PING_RESULT", function(id, time, dst)
 end)
 
 sys.taskInit(function()
+    local adapter = socket.LWIP_GP
+    local ip = "121.14.77.221"
+    -- icmp.debug(true)
+    if wlan and wlan.connect then
+        sys.wait(500)
+        wlan.init()
+        wlan.connect("luatos1234", "12341234")
+        adapter = socket.LWIP_STA
+        -- ip = "192.168.1.10"
+    end
     sys.waitUntil("IP_READY")
     sys.wait(1000)
-    icmp.setup(socket.LWIP_GP)
+    icmp.setup(adapter)
     while 1 do
-        icmp.ping(socket.LWIP_GP, "121.14.77.221")
+        log.info("执行PING操作", ip)
+        icmp.ping(adapter, ip)
         sys.waitUntil("PING_RESULT", 3000)
-        sys.wait(3000)
+        sys.wait(1000)
     end
 end)