Skip to content
Open
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 7)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 4)
set(AGENT_VERSION_BUILD 5)
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 demo/compose/adapter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ COPY --chown=adapter:adapter "./demo/agent/${LOG_FILE}" machine.log

EXPOSE 7878

CMD ["ruby", "run_scenario.rb", "-l", "-m", "30", "machine.log"]
CMD ["ruby", "run_scenario.rb", "-l", "-m", "1", "machine.log"]



8 changes: 4 additions & 4 deletions docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# base image - ubuntu has amd64, arm64 etc.
# 22.04 is the current long term support release, maintained until 2025-04.
FROM ubuntu:22.04 AS os
FROM ubuntu:24.04 AS os

# tzinfo hangs without this
ARG DEBIAN_FRONTEND='noninteractive'
Expand Down Expand Up @@ -62,7 +62,7 @@ RUN apt clean && apt update \
rake \
ruby \
&& rm -rf /var/lib/apt/lists/* \
&& pip install conan
&& pip install --break-system-packages --root-user-action ignore conan

# make an agent directory and cd into it
WORKDIR /root/agent
Expand Down Expand Up @@ -108,8 +108,8 @@ LABEL author='mtconnect' description='MTConnect C++ Agent'
# change to a new non-root user for better security.
# this also adds the user to a group with the same name.
# --create-home creates a home folder, ie /home/<username>
ARG UID=1000
ARG GID=1000
ARG UID=1001
ARG GID=1001

RUN groupadd \
--gid $GID \
Expand Down
5 changes: 5 additions & 0 deletions src/mtconnect/source/adapter/agent_adapter/session_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ namespace mtconnect::source::adapter::agent_adapter {
LOG(error) << "Agent Adapter Target: " << m_request->getTarget(m_url);
LOG(error) << "Agent Adapter " << what << ": " << ec.message() << "\n";
m_request.reset();

// Clear cached DNS resolution so hostname is re-resolved on reconnect.
// This handles DHCP environments where IP addresses may change.
m_resolution.reset();

if (m_failed)
m_failed(ec);
}
Expand Down
18 changes: 17 additions & 1 deletion src/mtconnect/source/adapter/shdr/connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ namespace mtconnect::source::adapter::shdr {
return true;
}

/// @brief Attempt to reconnect after a delay. If the server is a hostname, re-resolve it to get the current IP
/// address in case it has changed. If the server is a static IP address, just reconnect.
inline void Connector::asyncTryConnect()
{
NAMED_SCOPE("Connector::asyncTryConnect");
Expand All @@ -145,7 +147,21 @@ namespace mtconnect::source::adapter::shdr {
if (ec != boost::asio::error::operation_aborted)
{
LOG(info) << "reconnect: retrying connection";
asio::dispatch(m_strand, boost::bind(&Connector::connect, this));
// Re-resolve hostname to handle DHCP/dynamic IP environments.
// If the server is a hostname (not a static IP), re-resolve to get
// the current IP address in case it has changed.
boost::system::error_code addrEc;
ip::make_address(m_server, addrEc);
if (addrEc)
{
// m_server is a hostname, re-resolve it
asio::dispatch(m_strand, boost::bind(&Connector::resolve, this));
}
else
{
// m_server is a static IP address, just reconnect
asio::dispatch(m_strand, boost::bind(&Connector::connect, this));
}
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/mtconnect/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace mtconnect {
/// @brief Convert text to upper case
/// @param[in,out] text text
/// @return upper-case of text as string
constexpr std::string &toUpperCase(std::string &text)
inline std::string &toUpperCase(std::string &text)
{
std::transform(text.begin(), text.end(), text.begin(),
[](unsigned char c) { return std::toupper(c); });
Expand All @@ -209,7 +209,7 @@ namespace mtconnect {
/// @brief Simple check if a number as a string is negative
/// @param s the numbeer
/// @return `true` if positive
constexpr bool isNonNegativeInteger(const std::string &s)
inline bool isNonNegativeInteger(const std::string &s)
{
for (const char c : s)
{
Expand All @@ -223,7 +223,7 @@ namespace mtconnect {
/// @brief Checks if a string is a valid integer
/// @param s the string
/// @return `true` if is `[+-]\d+`
constexpr bool isInteger(const std::string &s)
inline bool isInteger(const std::string &s)
{
auto iter = s.cbegin();
if (*iter == '-' || *iter == '+')
Expand Down