Lua https timeout is not working

大憨熊 提交于 2019-12-20 05:16:08

问题


I am using following versions of Lua and it's packets on openWRT environment:

  • luasocket-2.0.2

  • luasec-0.4

  • lua-5.1.4

Trying to use timeout for a https.request call. Tried using https.TIMEOUT where local https = require("ssl.https") and it never time outs. I tried giving a very small timeout (I know that I won't get answer in that time and internet connection is OK) also I tried when net connection is disconnected once https.request is called. Is it a known issue? or shall I try something else for this. I can guess either send/recieve is blocking it for infinite time.

-Swapnel


回答1:


Setting the timeout on ssl.https does not work. You have to set it on socket.http.

For instance, if your code looks like this:

local https = require "ssl.https"
https.TIMEOUT = 0.01
b, c, h = https.request("https://www.google.fr/")

change it to this:

local http = require "socket.http"
local https = require "ssl.https"
http.TIMEOUT = 0.01
b, c, h = https.request("https://www.google.fr/")


来源:https://stackoverflow.com/questions/20193454/lua-https-timeout-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!