mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Set HTTP timeout.
PiperOrigin-RevId: 806439483
This commit is contained in:
committed by
Copybara-Service
parent
ea342c18f9
commit
70bb114778
@@ -192,6 +192,7 @@ cc_library(
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "absl/time/time.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
@@ -26,6 +28,7 @@ struct WebRequest {
|
||||
std::string method;
|
||||
std::multimap<std::string, std::string> headers;
|
||||
std::string body;
|
||||
absl::Duration timeout;
|
||||
};
|
||||
|
||||
struct WebResponse {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "internal/platform/implementation/windows/http_loader.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
@@ -23,6 +22,7 @@
|
||||
#include "absl/strings/numbers.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/implementation/http_loader.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
@@ -209,6 +209,21 @@ absl::Status HttpLoader::ConnectWebServer() {
|
||||
return absl::FailedPreconditionError(absl::StrCat(GetLastError()));
|
||||
}
|
||||
|
||||
// Set WinInet timeout if provided by caller.
|
||||
if (request_.timeout > absl::ZeroDuration() &&
|
||||
request_.timeout < absl::InfiniteDuration()) {
|
||||
DWORD timeout_ms = absl::ToInt64Milliseconds(request_.timeout);
|
||||
::InternetSetOptionA(internet_handle_, INTERNET_OPTION_CONNECT_TIMEOUT,
|
||||
reinterpret_cast<void*>(&timeout_ms),
|
||||
sizeof(timeout_ms));
|
||||
::InternetSetOptionA(internet_handle_, INTERNET_OPTION_SEND_TIMEOUT,
|
||||
reinterpret_cast<void*>(&timeout_ms),
|
||||
sizeof(timeout_ms));
|
||||
::InternetSetOptionA(internet_handle_, INTERNET_OPTION_RECEIVE_TIMEOUT,
|
||||
reinterpret_cast<void*>(&timeout_ms),
|
||||
sizeof(timeout_ms));
|
||||
}
|
||||
|
||||
connect_handle_ = InternetConnectA(internet_handle_, /*Internet*/
|
||||
host_.c_str(), /*Server name*/
|
||||
port_, /*Port*/
|
||||
|
||||
Reference in New Issue
Block a user