Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed two issues with disconnect and no termiinal '/' interpreted as topic #462

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 3)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 10)
set(AGENT_VERSION_BUILD 11)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ namespace mtconnect::configuration {
string host, protocol, path;
auto url = *GetOption<string>(options, configuration::Url);

boost::regex pat("^([^:]+)://([^:/]+)(:[0-9]+)?(/?.+)");
boost::regex pat("^([^:]+)://([^:/]+)(:[0-9]+)?(/.+)?");
boost::match_results<string::const_iterator> match;
if (boost::regex_match(url, match, pat))
{
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/configuration/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace mtconnect {
boost::optional<std::string> command;
boost::optional<std::string> config;

const char *argp[3] = {"agent", "run", (const char *) configFile};
const char *argp[3] = {"agent", "run", (const char *)configFile};
auto options = g_service->parseOptions(3, argp, command, config);
g_service->initialize(options);

Expand Down
24 changes: 17 additions & 7 deletions src/mtconnect/mqtt/mqtt_client_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace mtconnect {
m_password = GetOption<std::string>(options, configuration::MqttPassword);

std::stringstream url;
url << "mqtt://" << m_host << ':' << m_port;
url << "mqtt://" << m_host << ':' << m_port << '/';
m_url = url.str();

// Some brokers require specific ClientID provided.
Expand Down Expand Up @@ -153,7 +153,7 @@ namespace mtconnect {
else
{
LOG(info) << "MQTT ConnAck: MQTT connection failed: " << ec;
reconnect();
disconnected();
}
return true;
});
Expand All @@ -162,12 +162,9 @@ namespace mtconnect {
LOG(info) << "MQTT " << m_url << ": connection closed";
// Queue on a strand
m_connected = false;
if (m_handler && m_handler->m_disconnected)
m_handler->m_disconnected(shared_from_this());
m_handler->m_disconnected(shared_from_this());
if (m_running)
{
reconnect();
disconnected();
return true;
}
else
Expand All @@ -180,7 +177,7 @@ namespace mtconnect {
LOG(error) << "error: " << ec.message();
m_connected = false;
if (m_running)
reconnect();
disconnected();
});

client->set_publish_handler([this](mqtt::optional<std::uint16_t> packet_id,
Expand Down Expand Up @@ -359,6 +356,19 @@ namespace mtconnect {
m_handler->m_receive(shared_from_this(), string(topic), string(contents));
}

void disconnected()
{
NAMED_SCOPE("MqttClientImpl::disconnected");

LOG(info) << "Calling handler disconnected";

if (m_handler && m_handler->m_disconnected)
m_handler->m_disconnected(shared_from_this());

if (m_running)
reconnect();
}

/// <summary>
///
/// </summary>
Expand Down
Loading