]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Separate out expected.hh
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 9 Jul 2026 11:30:42 +0000 (13:30 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 9 Jul 2026 11:31:17 +0000 (13:31 +0200)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/Makefile.am
pdns/dnsdistdist/expected.hh [new symlink]
pdns/expected.hh [new file with mode: 0644]
pdns/iputils.hh
pdns/recursordist/expected.hh [new symlink]

index 934d1f400bd3d162301c52898e4f22a3313eb1b2..b385081d91811a8d531ce8864754ae7c5892ebdc 100644 (file)
@@ -1,4 +1,4 @@
-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 += \
@@ -237,6 +237,7 @@ pdns_server_SOURCES = \
        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 \
diff --git a/pdns/dnsdistdist/expected.hh b/pdns/dnsdistdist/expected.hh
new file mode 120000 (symlink)
index 0000000..aa08a48
--- /dev/null
@@ -0,0 +1 @@
+../expected.hh
\ No newline at end of file
diff --git a/pdns/expected.hh b/pdns/expected.hh
new file mode 100644 (file)
index 0000000..74128f6
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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);
+  }
+};
+}
index 4afcc9ac9e6009bad67d0f28dca74a23d5c9bad2..4bc6e9526acfb1ea5330370141454571b3efb9a5 100644 (file)
@@ -32,7 +32,7 @@
 #include <netdb.h>
 #include <sstream>
 #include <sys/un.h>
-#include <variant>
+#include "expected.hh"
 
 #include "namespaces.hh"
 
@@ -2078,51 +2078,6 @@ bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destinat
 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 */
diff --git a/pdns/recursordist/expected.hh b/pdns/recursordist/expected.hh
new file mode 120000 (symlink)
index 0000000..aa08a48
--- /dev/null
@@ -0,0 +1 @@
+../expected.hh
\ No newline at end of file