OGLplus
(0.59.0)
a C++ wrapper for rendering APIs
eagine
ssl_api
result.hpp
Go to the documentation of this file.
1
#ifndef EAGINE_SSL_API_RESULT_HPP
9
#define EAGINE_SSL_API_RESULT_HPP
10
11
#include "
config.hpp
"
12
#include <
eagine/anything.hpp
>
13
#include <
eagine/c_api_wrap.hpp
>
14
#include <
eagine/string_span.hpp
>
15
16
namespace
eagine::sslp {
17
//------------------------------------------------------------------------------
18
class
ssl_no_result_info {
19
public
:
20
constexpr
auto
error_code(anything) noexcept ->
auto
& {
21
return
*
this
;
22
}
23
24
constexpr
auto
message
() const noexcept ->
string_view
{
25
return
{
"OpenSSL function not available"
};
26
}
27
28
constexpr
auto
set_unknown_error() noexcept -> auto& {
29
return
*
this
;
30
}
31
};
32
//------------------------------------------------------------------------------
33
class
ssl_result_info {
34
public
:
35
explicit
constexpr
operator
bool() const noexcept {
36
return
_error_code == 0;
37
}
38
39
constexpr
auto
error_code(
unsigned
long
ec) noexcept ->
auto
& {
40
_error_code = ec;
41
return
*
this
;
42
}
43
44
constexpr
auto
set_unknown_error() noexcept -> auto& {
45
if
(!_error_code) {
46
_error_code = ~0UL;
47
}
48
return
*
this
;
49
}
50
51
auto
message
() const noexcept ->
string_view
{
52
// TODO: get error string from OpenSSL
53
return
{
"unknown ssl error"
};
54
}
55
56
private
:
57
unsigned
long
_error_code{0UL};
58
};
59
//------------------------------------------------------------------------------
60
template
<
typename
Result>
61
using
ssl_no_result = api_no_result<Result, ssl_no_result_info>;
62
//------------------------------------------------------------------------------
63
template
<
typename
Result>
64
using
ssl_result = api_result<Result, ssl_result_info>;
65
//------------------------------------------------------------------------------
66
template
<
typename
Result>
67
using
ssl_opt_result = api_opt_result<Result, ssl_result_info>;
68
//------------------------------------------------------------------------------
69
template
<
typename
Result, api_result_val
id
ity Val
id
ity>
70
inline
auto
71
collapse_bool(api_result<Result, ssl_result_info, Validity>&& r) noexcept {
72
return
r.collapsed(
73
[](
int
value) {
return
value == 1; },
74
[](
auto
&
info
) {
info
.set_unknown_error(); });
75
}
76
//------------------------------------------------------------------------------
77
}
// namespace eagine::sslp
78
79
#endif // EAGINE_SSL_API_RESULT_HPP
eagine::string_view
basic_string_span< const char > string_view
Alias for const string views.
Definition:
string_span.hpp:116
eagine::log_event_severity::info
@ info
Informational log entries.
c_api_wrap.hpp
config.hpp
eagine::msgbus::connection_protocol::message
@ message
Message protocol.
string_span.hpp
anything.hpp
Copyright © 2015-2021
Matúš Chochlík
.
<
chochlik -at -gmail.com
>
Documentation generated on Tue Apr 13 2021 by
Doxygen
(version 1.8.17).