Browse Source

update: demo,netdrv,ch390,演示tcp连接失败时事件回调

https://gitee.com/openLuat/LuatOS/issues/ICN3ZD
Wendal Chen 6 months ago
parent
commit
239a9a0cc5

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

@@ -483,6 +483,7 @@ netdrv.event_subscribe(socket.LWIP_ETH, netdrv.EVT_SOCKET, function(id, event, p
         - connected 连接成功
         - closed 连接关闭
         - remote_close 远程关闭
+        - timeout dns解析超时,或者tcp连接超时
         - error 错误,包括一切异常错误
         - dns_result dns解析结果, 如果remote_ip为0.0.0.0,表示解析失败
     -- params是参数表

+ 9 - 2
luat/demo/netdrv/ch390h/wan.lua

@@ -61,9 +61,16 @@ sys.taskInit(function()
     end
     while 1 do
         sys.wait(6000)
+        -- 正常请求
         local code, headers, body = http.request("GET", "http://httpbin.air32.cn/bytes/4096", nil, nil, {adapter=socket.LWIP_ETH}).wait()
         log.info("http", code, headers, body and #body)
-        log.info("lua", rtos.meminfo())
-        log.info("sys", rtos.meminfo("sys"))
+        -- 故意失败1
+        local code, headers, body = http.request("GET", "http://httpbin.air323.cn/status/404", nil, nil, {adapter=socket.LWIP_ETH, timeout=5000}).wait()
+        log.info("http", code, headers, body and #body)
+        -- 故意失败2
+        local code, headers, body = http.request("GET", "http://112.125.89.8:40000/status/404", nil, nil, {adapter=socket.LWIP_ETH, timeout=5000}).wait()
+        log.info("http", code, headers, body and #body)
+        -- log.info("lua", rtos.meminfo())
+        -- log.info("sys", rtos.meminfo("sys"))
     end
 end)