From 20f7f2fd5d99a1c4feeef23a38910a26d862af71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korina=20=C5=A0imi=C4=8Devi=C4=87?= Date: Fri, 23 Feb 2024 10:48:21 +0100 Subject: [PATCH] Add Windows specific error codes to should-reconnect condition Summary: related to T11798 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D28103 --- include/async_mqtt5/impl/read_op.hpp | 6 +++++- include/async_mqtt5/impl/write_op.hpp | 9 ++++++--- test/integration/cancellation.cpp | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/async_mqtt5/impl/read_op.hpp b/include/async_mqtt5/impl/read_op.hpp index 741a175..1071644 100644 --- a/include/async_mqtt5/impl/read_op.hpp +++ b/include/async_mqtt5/impl/read_op.hpp @@ -110,10 +110,14 @@ private: static bool should_reconnect(error_code ec) { using namespace asio::error; - return ec == connection_aborted || ec == not_connected || + // note: Win ERROR_SEM_TIMEOUT == Posix ENOLINK (Reserved) + return ec.value() == 1236L || /* Win ERROR_CONNECTION_ABORTED */ + ec.value() == 121L || /* Win ERROR_SEM_TIMEOUT */ + ec == connection_aborted || ec == not_connected || ec == timed_out || ec == connection_reset || ec == broken_pipe || ec == asio::error::eof; } + }; diff --git a/include/async_mqtt5/impl/write_op.hpp b/include/async_mqtt5/impl/write_op.hpp index 690fae9..b001815 100644 --- a/include/async_mqtt5/impl/write_op.hpp +++ b/include/async_mqtt5/impl/write_op.hpp @@ -91,9 +91,12 @@ private: static bool should_reconnect(error_code ec) { using namespace asio::error; - return ec == connection_aborted || ec == not_connected - || ec == timed_out || ec == connection_reset - || ec == broken_pipe || ec == asio::error::eof; + // note: Win ERROR_SEM_TIMEOUT == Posix ENOLINK (Reserved) + return ec.value() == 1236L || /* Win ERROR_CONNECTION_ABORTED */ + ec.value() == 121L || /* Win ERROR_SEM_TIMEOUT */ + ec == connection_aborted || ec == not_connected || + ec == timed_out || ec == connection_reset || + ec == broken_pipe || ec == asio::error::eof; } }; diff --git a/test/integration/cancellation.cpp b/test/integration/cancellation.cpp index 2f7a834..a37f669 100644 --- a/test/integration/cancellation.cpp +++ b/test/integration/cancellation.cpp @@ -255,7 +255,7 @@ struct shared_test_data { const std::string topic = "topic"; const std::string payload = "payload"; - const publish_props pub_props; + const publish_props pub_props {}; const std::string publish_qos1 = encoders::encode_publish( 1, topic, payload, qos_e::at_least_once, retain_e::no, dup_e::no, {}