Repository navigation
Expand file tree
/
Copy pathconsumer_v3_native_server.cpp
More file actions
126 lines (113 loc) · 5.43 KB
/
Copy pathconsumer_v3_native_server.cpp
File metadata and controls
126 lines (113 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
This file is part of libhttpserver
Copyright (C) 2011-2026 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the file
LICENSE in the distribution; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
// Public headers compile without internal macros; compiled behavior uses library linkage.
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
#include <httpserver/exchange.hpp>
#include <httpserver/http/method.hpp>
#include <httpserver/http/outcome.hpp>
#include <httpserver/server/options.hpp>
#include <httpserver/server/server.hpp>
// Name every lifecycle member once, all unevaluated (decltype over
// declval): the compiler checks the signatures without emitting a
// single call, so nothing links against the library.
int shape_of_native_server() {
using httpserver::exchange;
using httpserver::task;
namespace http = httpserver::http;
namespace srv = httpserver::server;
srv::server_options options;
srv::listener_options listener;
listener.address = "127.0.0.1";
listener.port = 0;
options.add_listener(listener);
options.timeouts().header = std::chrono::milliseconds(30000);
const std::size_t count = options.listener_count();
srv::route_handler handler = [](exchange&) -> task<void> {
co_return;
};
const http::method get = http::method::known(http::method_id::get);
using server_ref = srv::native_server&;
static_assert(std::is_same_v<decltype(std::declval<server_ref>().readiness()),
srv::readiness_driver*>);
static_assert(noexcept(std::declval<server_ref>().readiness()));
options.loop() = srv::loop_mode::external;
static_assert(std::is_same_v<decltype(std::declval<const srv::server_options&>().loop()),
const srv::loop_mode&>);
static_assert(
std::is_same<decltype(std::declval<server_ref>().route(
get, "/health", std::move(handler))),
http::outcome>::value,
"route() returns the typed outcome");
static_assert(
std::is_same<decltype(std::declval<server_ref>().listen()),
http::outcome>::value,
"listen() returns the typed outcome");
static_assert(
std::is_same<decltype(std::declval<server_ref>().get_bound_port(0)),
std::uint16_t>::value,
"get_bound_port() resolves the bound port");
static_assert(
std::is_same<decltype(std::declval<server_ref>().is_running()),
bool>::value,
"is_running() reports the lifecycle state");
static_assert(!std::is_copy_constructible<srv::native_server>::value,
"native_server is not copyable");
static_assert(std::is_constructible<srv::native_server,
srv::server_options>::value,
"native_server constructs from server_options alone");
// TASK-110: the drain surface. Everything stays unevaluated (no
// ticket object is ever destroyed here -- its special members live
// in the library this sentinel deliberately does not link).
using ticket_ref = srv::drain_ticket&;
static_assert(
std::is_same<decltype(std::declval<ticket_ref>().wait(
std::declval<srv::drain_result&>())),
http::outcome>::value,
"drain_ticket::wait returns the typed outcome");
static_assert(
std::is_same<decltype(std::declval<server_ref>().begin_drain(
std::chrono::milliseconds(100),
std::declval<srv::drain_ticket&>())),
http::outcome>::value,
"begin_drain returns the typed outcome");
static_assert(!std::is_copy_constructible<srv::drain_ticket>::value,
"drain_ticket is not copyable");
static_assert(std::is_move_constructible<srv::drain_ticket>::value,
"drain_ticket is move-constructible");
static_assert(std::is_move_assignable<srv::drain_ticket>::value,
"drain_ticket is move-assignable");
static_assert(std::is_default_constructible<srv::drain_ticket>::value,
"drain_ticket is default-constructible (the empty shape)");
static_assert(
std::is_same<decltype(std::declval<srv::drain_result>().status),
srv::drain_status>::value
&& std::is_same<
decltype(std::declval<srv::drain_result>().remaining),
std::size_t>::value,
"drain_result reports status and remaining");
static_assert(std::is_enum<srv::drain_status>::value,
"drain_status is the two-state enumeration");
return count == 1 ? 0 : 1;
}
int main() {
return shape_of_native_server() == 0 ? 0 : 0;
}