diff --git a/include/kafka/KafkaProducer.h b/include/kafka/KafkaProducer.h index 1ca124c24..f9bddd52f 100644 --- a/include/kafka/KafkaProducer.h +++ b/include/kafka/KafkaProducer.h @@ -54,7 +54,7 @@ class KafkaProducer: public KafkaClient * Possible error values: * - RD_KAFKA_RESP_ERR__TIMED_OUT: The `timeout` was reached before all outstanding requests were completed. */ - Error flush(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()); + Error flush(std::chrono::milliseconds timeout = InfiniteTimeout); /** * Purge messages currently handled by the KafkaProducer. @@ -64,7 +64,7 @@ class KafkaProducer: public KafkaClient /** * Close this producer. This method would wait up to timeout for the producer to complete the sending of all incomplete requests (before purging them). */ - void close(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()); + void close(std::chrono::milliseconds timeout = InfiniteTimeout); /** * Options for sending messages. @@ -142,7 +142,7 @@ class KafkaProducer: public KafkaClient /** * Needs to be called before any other methods when the transactional.id is set in the configuration. */ - void initTransactions(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()); + void initTransactions(std::chrono::milliseconds timeout = InfiniteTimeout); /** * Should be called before the start of each new transaction. @@ -152,12 +152,12 @@ class KafkaProducer: public KafkaClient /** * Commit the ongoing transaction. */ - void commitTransaction(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()); + void commitTransaction(std::chrono::milliseconds timeout = InfiniteTimeout); /** * Abort the ongoing transaction. */ - void abortTransaction(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()); + void abortTransaction(std::chrono::milliseconds timeout = InfiniteTimeout); /** diff --git a/include/kafka/Project.h b/include/kafka/Project.h index 9ab1bf086..21560b87b 100644 --- a/include/kafka/Project.h +++ b/include/kafka/Project.h @@ -10,9 +10,6 @@ // #define KAFKA_API_ENABLE_UNIT_TEST_STUBS // #endif -#if defined(WIN32) && !defined(NOMINMAX) -#define NOMINMAX -#endif #if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) #define COMPILER_SUPPORTS_CPP_17 1 diff --git a/include/kafka/Types.h b/include/kafka/Types.h index e843f902d..3d04b7e07 100644 --- a/include/kafka/Types.h +++ b/include/kafka/Types.h @@ -60,6 +60,17 @@ class ConstBuffer std::size_t _size; }; + +/** + * Infinite timeout. + */ +#if COMPILER_SUPPORTS_CPP_17 +const inline std::chrono::milliseconds InfiniteTimeout = (std::chrono::milliseconds::max)(); +#else +const static std::chrono::milliseconds InfiniteTimeout = (std::chrono::milliseconds::max)(); +#endif + + /** * Topic name. */ diff --git a/include/kafka/addons/KafkaRecoverableProducer.h b/include/kafka/addons/KafkaRecoverableProducer.h index b87cce8e7..c9ba74044 100644 --- a/include/kafka/addons/KafkaRecoverableProducer.h +++ b/include/kafka/addons/KafkaRecoverableProducer.h @@ -138,7 +138,7 @@ class KafkaRecoverableProducer * Possible error values: * - RD_KAFKA_RESP_ERR__TIMED_OUT: The `timeout` was reached before all outstanding requests were completed. */ - Error flush(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) + Error flush(std::chrono::milliseconds timeout = InfiniteTimeout) { std::lock_guard lock(_producerMutex); @@ -158,7 +158,7 @@ class KafkaRecoverableProducer /** * Close this producer. This method would wait up to timeout for the producer to complete the sending of all incomplete requests (before purging them). */ - void close(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) + void close(std::chrono::milliseconds timeout = InfiniteTimeout) { std::lock_guard lock(_producerMutex); @@ -247,7 +247,7 @@ class KafkaRecoverableProducer /** * Needs to be called before any other methods when the transactional.id is set in the configuration. */ - void initTransactions(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) + void initTransactions(std::chrono::milliseconds timeout = InfiniteTimeout) { std::lock_guard lock(_producerMutex); @@ -267,7 +267,7 @@ class KafkaRecoverableProducer /** * Commit the ongoing transaction. */ - void commitTransaction(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) + void commitTransaction(std::chrono::milliseconds timeout = InfiniteTimeout) { std::lock_guard lock(_producerMutex); @@ -277,7 +277,7 @@ class KafkaRecoverableProducer /** * Abort the ongoing transaction. */ - void abortTransaction(std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) + void abortTransaction(std::chrono::milliseconds timeout = InfiniteTimeout) { std::lock_guard lock(_producerMutex);