Networking: add timeout support for TCP connecting

This commit is contained in:
李通洲
2024-03-20 14:25:59 +08:00
committed by Carter Li
parent 85da30ccf5
commit 75927a87b2
4 changed files with 28 additions and 4 deletions
+3 -1
View File
@@ -13,6 +13,8 @@ void ffPreparePublicIp(FFPublicIpOptions* options)
exit(1);
}
state.timeout = options->timeout;
if (options->url.length == 0)
status = ffNetworkingSendHttpRequest(&state, "ipinfo.io", "/json", NULL);
else
@@ -49,7 +51,7 @@ const char* ffDetectPublicIp(FFPublicIpOptions* options, FFPublicIpResult* resul
return status;
FF_STRBUF_AUTO_DESTROY response = ffStrbufCreateA(4096);
const char* error = ffNetworkingRecvHttpResponse(&state, &response, options->timeout);
const char* error = ffNetworkingRecvHttpResponse(&state, &response);
if (error == NULL)
ffStrbufSubstrAfterFirstS(&response, "\r\n\r\n");
else
+3 -1
View File
@@ -12,6 +12,8 @@ void ffPrepareWeather(FFWeatherOptions* options)
exit(1);
}
state.timeout = options->timeout;
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/");
if (options->location.length)
ffStrbufAppend(&path, &options->location);
@@ -29,7 +31,7 @@ const char* ffDetectWeather(FFWeatherOptions* options, FFstrbuf* result)
return status;
ffStrbufEnsureFree(result, 4095);
const char* error = ffNetworkingRecvHttpResponse(&state, result, options->timeout);
const char* error = ffNetworkingRecvHttpResponse(&state, result);
if (error == NULL)
{
ffStrbufSubstrAfterFirstS(result, "\r\n\r\n");