diff --git a/service/qos/qos_common.cc b/service/qos/qos_common.cc index a56a8c5cf5..26be4391da 100644 --- a/service/qos/qos_common.cc +++ b/service/qos/qos_common.cc @@ -41,4 +41,22 @@ service_level_options service_level_options::replace_defaults(const service_leve return ret; } +service_level_options service_level_options::merge_with(const service_level_options& other) const { + service_level_options ret = *this; + std::visit(overloaded_functor { + [&] (const unset_marker& um) { + ret.timeout = other.timeout; + }, + [&] (const delete_marker& dm) { + ret.timeout = other.timeout; + }, + [&] (const lowres_clock::duration& d) { + if (auto* other_timeout = std::get_if(&other.timeout)) { + ret.timeout = std::min(d, *other_timeout); + } + }, + }, ret.timeout); + return ret; +} + } diff --git a/service/qos/qos_common.hh b/service/qos/qos_common.hh index b4b79f8568..54845a17c5 100644 --- a/service/qos/qos_common.hh +++ b/service/qos/qos_common.hh @@ -49,6 +49,9 @@ struct service_level_options { timeout_type timeout = unset_marker{}; service_level_options replace_defaults(const service_level_options& other) const; + // Merges the values of two service level options. The semantics depends + // on the type of the parameter - e.g. for timeouts, a min value is preferred. + service_level_options merge_with(const service_level_options& other) const; bool operator==(const service_level_options& other) const = default; bool operator!=(const service_level_options& other) const = default;