-JSON11_LIBS = $(top_builddir)/ext/json11/libjson11.la
+sJSON11_LIBS = $(top_builddir)/ext/json11/libjson11.la
ARC4RANDOM_LIBS = $(top_builddir)/ext/arc4random/libarc4random.la
AM_CPPFLAGS += \
ednscookies.cc ednscookies.hh \
ednsoptions.cc ednsoptions.hh \
ednssubnet.cc ednssubnet.hh \
+ expected.hh \
gettime.cc gettime.hh \
gss_context.cc gss_context.hh \
histogram.hh \
--- /dev/null
+../expected.hh
\ No newline at end of file
--- /dev/null
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ */
+#pragma once
+
+#include <variant>
+
+// A poor man's std::expected, which only becomes available for real with C++23
+
+namespace pdns
+{
+template <class E>
+class unexpected
+{
+public:
+ unexpected(const E& arg) :
+ err(arg) {}
+ const E& error() const
+ {
+ return err;
+ }
+
+private:
+ E err;
+};
+
+template <class T, class E>
+class expected : private std::variant<T, E>
+{
+public:
+ expected(const T& arg) :
+ std::variant<T, E>(arg) {}
+
+ expected(const unexpected<E>& arg) :
+ std::variant<T, E>(arg.error()) {}
+
+ [[nodiscard]] bool has_value() const
+ {
+ return std::holds_alternative<T>(*this);
+ }
+
+ const T& value() const
+ {
+ return std::get<T>(*this);
+ }
+ const E& error() const
+ {
+ return std::get<E>(*this);
+ }
+};
+}
#include <netdb.h>
#include <sstream>
#include <sys/un.h>
-#include <variant>
+#include "expected.hh"
#include "namespaces.hh"
bool HarvestTimestamp(struct msghdr* msgh, struct timeval* timeval);
void fillMSGHdr(struct msghdr* msgh, struct iovec* iov, cmsgbuf_aligned* cbuf, size_t cbufsize, char* data, size_t datalen, ComboAddress* addr);
int sendOnNBSocket(int fileDesc, const struct msghdr* msgh);
-
-// A poor man's std::expected, which only becomes available for real with C++23
-namespace pdns
-{
-template <class E>
-class unexpected
-{
-public:
- unexpected(const E& arg) :
- err(arg) {}
- const E& error() const
- {
- return err;
- }
-
-private:
- E err;
-};
-
-template <class T, class E>
-class expected : private std::variant<T, E>
-{
-public:
- expected(const T& arg) :
- std::variant<T, E>(arg) {}
-
- expected(const unexpected<E>& arg) :
- std::variant<T, E>(arg.error()) {}
-
- [[nodiscard]] bool has_value() const
- {
- return std::holds_alternative<T>(*this);
- }
-
- const T& value() const
- {
- return std::get<T>(*this);
- }
- const E& error() const
- {
- return std::get<E>(*this);
- }
-};
-}
-
[[nodiscard]] pdns::expected<size_t, int> sendMsgWithOptions(int socketDesc, const void* buffer, size_t len, const ComboAddress* dest, const ComboAddress* local, unsigned int localItf, int flags);
/* requires a non-blocking, connected TCP socket */
--- /dev/null
+../expected.hh
\ No newline at end of file