10Duke Enterprise C++ SDK
Toggle main menu visibility
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
10
namespace
tenduke
{
namespace
http
{
namespace
win {
11
15
class
InternetHandle
16
{
17
public
:
18
virtual
~InternetHandle
()
19
{
20
try
{
21
close
();
22
}
23
// Ignore any exceptions: Throwing from destructors leads to undefined behavior
24
catch
(
::tenduke::TendukeException
&e) {
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
61
public
:
62
::HINTERNET handle;
63
};
64
65
}}}
66
67
#endif
//TENDUKE_HTTP_WIN_INTERNETHANDLE_H
InternetHandle::InternetHandle
InternetHandle(const ::HINTERNET handle)
Constructs a new instance.
Definition
InternetHandle.h:33
tenduke::TendukeException
Base class for exceptions thrown by 10Duke C++ clients.
Definition
TendukeException.h:13
tenduke::http::win::InternetHandle::InternetHandle
InternetHandle(const ::HINTERNET handle)
Constructs a new instance.
Definition
InternetHandle.h:33
tenduke::http::win::InternetHandle::close
void close()
Closes the handle.
Definition
InternetHandle.h:45
tenduke::http
HTTP-related services.
Definition
BadRequest.h:6
tenduke::log::warning
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition
log.cpp:94
tenduke
Root for classes, functions and globals of 10Duke C++ Client.
Definition
APIRequest.h:4
core
services
windows
src
http
InternetHandle.h
Generated by
1.17.0