10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
InternetHandle.h
1#ifndef TENDUKE_HTTP_WIN_INTERNETHANDLE_H
2#define TENDUKE_HTTP_WIN_INTERNETHANDLE_H
3
4#include <windows.h>
5#include <winhttp.h>
6#include "../win32_utils.h"
7#include "TendukeException.h"
8#include "log/log.h"
9
10namespace tenduke { namespace http { namespace win {
11
16{
17public:
18 virtual ~InternetHandle()
19 {
20 try {
21 close();
22 }
23 // Ignore any exceptions: Throwing from destructors leads to undefined behavior
25 ::tenduke::log::warning(std::string("WinHttpCloseHandle failed. Ignored. Reason: ") + e.what());
26 }
27 }
28
33 explicit InternetHandle(const ::HINTERNET handle)
34 : handle(handle)
35 {
36 }
37
45 void close()
46 {
47 if (handle == nullptr) {
48 return;
49 }
50
51 const auto handleToClose = handle;
52 handle = nullptr;
53 const auto ok = ::WinHttpCloseHandle(handleToClose);
54
55 // Closing failed
56 if (!ok) {
57 ::tenduke::osa::win::throwOnHttpError(::GetLastError());
58 }
59 }
60
61public:
62 ::HINTERNET handle;
63};
64
65}}}
66
67#endif //TENDUKE_HTTP_WIN_INTERNETHANDLE_H
InternetHandle(const ::HINTERNET handle)
Constructs a new instance.
Definition InternetHandle.h:33
Base class for exceptions thrown by 10Duke C++ clients.
Definition TendukeException.h:13
InternetHandle(const ::HINTERNET handle)
Constructs a new instance.
Definition InternetHandle.h:33
void close()
Closes the handle.
Definition InternetHandle.h:45
HTTP-related services.
Definition BadRequest.h:6
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition log.cpp:94
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4