]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Long overdue table driven option setting for libfstrm
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 6 Oct 2020 13:39:16 +0000 (15:39 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 6 Oct 2020 13:39:16 +0000 (15:39 +0200)
pdns/fstrm_logger.cc

index 9e5608f94703c8bdfa1dac85af6ba857d25f0d7c..dba6c26132cdca2ff67f70a5f9225d86c673dacc 100644 (file)
@@ -84,43 +84,26 @@ FrameStreamLogger::FrameStreamLogger(const int family, const std::string& addres
       throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_queue_model failed: " + std::to_string(res));
     }
 
-    if (options.find("bufferHint") != options.end() && options.at("bufferHint")) {
-      res = fstrm_iothr_options_set_buffer_hint(d_iothropt, options.at("bufferHint"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_buffer_hint failed: " + std::to_string(res));
+    const struct {
+      const char *name;
+      fstrm_res (*function)(struct fstrm_iothr_options *, const unsigned int);
+    } list[] = {
+      { "bufferHint", fstrm_iothr_options_set_buffer_hint },
+      { "flushTimeout", fstrm_iothr_options_set_flush_timeout },
+      { "inputQueueSize", fstrm_iothr_options_set_input_queue_size },
+      { "outputQueueSize", fstrm_iothr_options_set_output_queue_size },
+      { "queueNotifyThreshold", fstrm_iothr_options_set_queue_notify_threshold },
+      { "setReopenInterval", fstrm_iothr_options_set_reopen_interval }
+    };
+
+    for (const auto& i : list) {
+      if (options.find(i.name) != options.end() && options.at(i.name)) {
+        fstrm_res r = i.function(d_iothropt, options.at(i.name));
+        if (r != fstrm_res_success) {
+          throw std::runtime_error("FrameStreamLogger: setting " + string(i.name) + " failed: " + std::to_string(r));
+        }
       }
     }
-    if (options.find("flushTimeout") != options.end() && options.at("flushTimeout")) {
-      res = fstrm_iothr_options_set_flush_timeout(d_iothropt, options.at("flushTimeout"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_flush_timeout failed: " + std::to_string(res));
-      }
-    }
-    if (options.find("inputQueueSize") != options.end() && options.at("inputQueueSize")) {
-      res = fstrm_iothr_options_set_input_queue_size(d_iothropt, options.at("inputQueueSize"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_input_queue_size failed: " + std::to_string(res));
-      }
-    }
-    if (options.find("outputQueueSize") != options.end() && options.at("outputQueueSize")) {
-      res = fstrm_iothr_options_set_output_queue_size(d_iothropt, options.at("outputQueueSize"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_output_queue_size failed: " + std::to_string(res));
-      }
-    }
-    if (options.find("queueNotifyThreshold") != options.end() && options.at("queueNotifyThreshold")) {
-      res = fstrm_iothr_options_set_queue_notify_threshold(d_iothropt, options.at("queueNotifyThreshold"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_queue_notify_threshold failed: " + std::to_string(res));
-      }
-    }
-    if (options.find("setReopenInterval") != options.end() && options.at("setReopenInterval")) {
-      res = fstrm_iothr_options_set_reopen_interval(d_iothropt, options.at("setReopenInterval"));
-      if (res != fstrm_res_success) {
-        throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_reopen_interval failed: " + std::to_string(res));
-      }
-    }
-
 
     if (connect) {
       d_iothr = fstrm_iothr_init(d_iothropt, &d_writer);