Repository navigation
Expand file tree
/
Copy pathoutcome.hpp
More file actions
91 lines (73 loc) · 3.19 KB
/
Copy pathoutcome.hpp
File metadata and controls
91 lines (73 loc) · 3.19 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
/*
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
*/
#ifndef SRC_HTTPSERVER_HTTP_OUTCOME_HPP_
#define SRC_HTTPSERVER_HTTP_OUTCOME_HPP_
#include <cstdint>
#include <string>
#include <utility>
namespace httpserver {
namespace http {
// Typed outcome codes for libhttpserver v3 operations. The taxonomy is
// entirely libhttpserver-owned (PRD-V3N-REQ-037): no backend, OS, or
// third-party numeric identifiers appear here or ever will. The list
// is extensible; values are ABI before the v3.0 freeze.
enum class outcome_code : std::uint8_t {
ok = 0, // operation completed successfully
invalid_argument, // caller passed a bad value
invalid_state, // e.g. terminal action already taken
limit_exceeded, // documented budget exceeded (bodies, fields, queues)
protocol_error, // peer sent something the engine must reject
not_supported, // protocol/feature not enabled in this build or config
connection_closed,
cancelled, // cancellation completed the operation
timeout,
would_deadlock, // e.g. drain-ticket wait from counted work (DR-V3-008)
peer_refused, // the peer policy refused admission (TASK-119)
};
// Operation result for API surface that can fail. Default-constructed
// to ok; error outcomes carry a human-readable diagnostic. The generic
// result<T> template that transports an outcome lands with the task
// plumbing; outcome is the error vocabulary it will carry.
class outcome {
public:
constexpr outcome() noexcept = default;
outcome(outcome_code code, std::string message) noexcept
: code_(code), message_(std::move(message)) { }
constexpr bool ok() const noexcept {
return code_ == outcome_code::ok;
}
constexpr outcome_code code() const noexcept {
return code_;
}
// Diagnostic text; empty for ok outcomes.
const std::string& message() const noexcept {
return message_;
}
// Shared ok instance for `return outcome::okay();` at call sites
// that cannot fail on the path in question.
static const outcome& okay() noexcept {
static const outcome ok_instance;
return ok_instance;
}
private:
outcome_code code_ = outcome_code::ok;
std::string message_;
};
} // namespace http
} // namespace httpserver
#endif // SRC_HTTPSERVER_HTTP_OUTCOME_HPP_