I did a multithreaded code to implement timeout for https. (Call the thread and sleep for small intervals of time until either the thread is done or the times add up to timeout)
but now I was told that if the https calls are made in succession without waiting for one to finish it causes bugs from getting data from their API (Lootlocker, which it does) So I then realized I needed to kill any https request threads that took to long, since the game had already moved on from them and they were still calling in the background. But not all systems support killing threads and thr:kill isn't a thing anymore.
Any fixes to kill/stop this thread while still leaving a timeout feature
Thread killing help with HTTPS
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1142
- Joined: Thu Dec 10, 2020 1:57 am
Re: Thread killing help with HTTPS
What happens if you set thread to nil?
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Thread killing help with HTTPS
Love doesn't support stopping threads externally. You'll have to check if the HTTPS library itself supports a timeout.
- Gunroar:Cannon()
- Party member
- Posts: 1142
- Joined: Thu Dec 10, 2020 1:57 am
Re: Thread killing help with HTTPS
Luahttps doest support timeout. I made a topic about this before with little response so I made my own timeout. Worked fine if not for that issue of stopping unused threads.
Re: Thread killing help with HTTPS
It's not really a timeout IMO, which is something that's supported by the socket functionality of the OS.
Using child threads is just passing the problem to them. It might not block the main thread anymore, but the child threads will stay blocked.
LuaHTTPS uses different platform libraries for HTTP/S messaging, and each has their own way of setting a connection timeout:
- WinINet: InternetSetOption() setter, with the INTERNET_OPTION_CONNECT_TIMEOUT / INTERNET_OPTION_RECEIVE_TIMEOUT etc flags and timeout values.
- Java HttpURLConnection: setConnectTimeout() / setReadTimeout() setters.
- Apple NSMutableRequest: the timeoutInterval field.
- libCURL: the easy_setopt() setter with the CURLOPT_TIMEOUT (_MS) flags, and the timeout value.
...and so on.
LuaHTTPS is an open source project, so I'm sure if you made a pull-request with the code for those, it would be welcomed.
Edit: ah, there's a list of all the backends (supported platforms) in here: https://github.com/love2d/lua-https/blo ... pp#L46-L67
Edit 2: rather re-write this as a proper next post.
Using child threads is just passing the problem to them. It might not block the main thread anymore, but the child threads will stay blocked.
LuaHTTPS uses different platform libraries for HTTP/S messaging, and each has their own way of setting a connection timeout:
- WinINet: InternetSetOption() setter, with the INTERNET_OPTION_CONNECT_TIMEOUT / INTERNET_OPTION_RECEIVE_TIMEOUT etc flags and timeout values.
- Java HttpURLConnection: setConnectTimeout() / setReadTimeout() setters.
- Apple NSMutableRequest: the timeoutInterval field.
- libCURL: the easy_setopt() setter with the CURLOPT_TIMEOUT (_MS) flags, and the timeout value.
...and so on.
LuaHTTPS is an open source project, so I'm sure if you made a pull-request with the code for those, it would be welcomed.
Edit: ah, there's a list of all the backends (supported platforms) in here: https://github.com/love2d/lua-https/blo ... pp#L46-L67
Edit 2: rather re-write this as a proper next post.
Last edited by RNavega on Fri Nov 15, 2024 12:00 am, edited 3 times in total.
Re: Thread killing help with HTTPS
Oh okay, I think I get it now.
In LuaHTTPS, you have some backends that are directly implemented as subclasses of HTTPSClient.
Those client implementations have their own API-specific ways of setting the timeout limits like I mentioned before. At the moment, these backends are CURL, Android, WinINet and Apple.
For the other backends they are not implemented as HTTPSClient, they just implement the connection part, and then use a generic client (ConnectionClient) that does inherit from HTTPSClient.
At the moment all of the connection-only backends use the PlaintextConnection class, a wrapper on a POSIX or WINSOCK raw socket. So by adding the timeout setup to the PlaintextConnection implementation you'd support all of the connection backends, which at the moment are the OpenSSL and the [Windows-only] SChannel backends.
(See src/common/HTTPS.cpp for the full backend list.)
All backends are then made available to Lua through the src/lua/main.cpp module. In there you'd add the extra lines to support a new parameter like "timeout" or whatever that adds the timeout value to the HTTPSClient::Request object that will be used for making the request.
The final use would be something like:
In LuaHTTPS, you have some backends that are directly implemented as subclasses of HTTPSClient.
Those client implementations have their own API-specific ways of setting the timeout limits like I mentioned before. At the moment, these backends are CURL, Android, WinINet and Apple.
For the other backends they are not implemented as HTTPSClient, they just implement the connection part, and then use a generic client (ConnectionClient) that does inherit from HTTPSClient.
At the moment all of the connection-only backends use the PlaintextConnection class, a wrapper on a POSIX or WINSOCK raw socket. So by adding the timeout setup to the PlaintextConnection implementation you'd support all of the connection backends, which at the moment are the OpenSSL and the [Windows-only] SChannel backends.
(See src/common/HTTPS.cpp for the full backend list.)
All backends are then made available to Lua through the src/lua/main.cpp module. In there you'd add the extra lines to support a new parameter like "timeout" or whatever that adds the timeout value to the HTTPSClient::Request object that will be used for making the request.
The final use would be something like:
Code: Select all
local url = "http://example.com"
local params = {method = "post", headers = {}, data = "cake", timeout = 16}
local code, body, headers = https.request(url, params)
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 12 guests