You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2024/05/09 03:03:25 UTC

(logging-log4cxx) branch telnet_appender updated: Make setMaxConnections safe to call when telnet appender is active

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch telnet_appender
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/telnet_appender by this push:
     new f31c1d0a Make setMaxConnections safe to call when telnet appender is active
f31c1d0a is described below

commit f31c1d0a9771b1015f0565e3e7392d7deee3b0d8
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Thu May 9 12:55:01 2024 +1000

    Make setMaxConnections safe to call when telnet appender is active
---
 src/main/cpp/telnetappender.cpp               | 14 +++++++++++++-
 src/main/include/log4cxx/net/telnetappender.h |  5 +++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/main/cpp/telnetappender.cpp b/src/main/cpp/telnetappender.cpp
index 38ad73a9..fd8e98f2 100644
--- a/src/main/cpp/telnetappender.cpp
+++ b/src/main/cpp/telnetappender.cpp
@@ -340,7 +340,19 @@ int TelnetAppender::getMaxConnections() const
 
 void TelnetAppender::setMaxConnections(int newValue)
 {
-	_priv->connections.resize(newValue);
+	std::lock_guard<std::recursive_mutex> lock(_priv->mutex);
+	if (_priv->connections.size() < newValue)
+		_priv->connections.resize(newValue);
+	else while (newValue < _priv->connections.size())
+	{
+		auto item = _priv->connections.back();
+		_priv->connections.pop_back()
+		if (item)
+		{
+			item->close();
+			--_priv->activeConnections;
+		}
+	}
 }
 
 bool TelnetAppender::requiresLayout() const
diff --git a/src/main/include/log4cxx/net/telnetappender.h b/src/main/include/log4cxx/net/telnetappender.h
index 4b0f383a..6af888c4 100644
--- a/src/main/include/log4cxx/net/telnetappender.h
+++ b/src/main/include/log4cxx/net/telnetappender.h
@@ -36,8 +36,9 @@ clients that connect to the TCP port.
 
 This allows logging output to be monitored using TCP/IP.
 To receive log data, use telnet to connect to the configured port number.
-This is handy for remote monitoring, especially when monitoring a
-servlet.
+
+TelnetAppender is most useful as a secondary appender,
+especially when monitoring a servlet remotely.
 
 If no layout is provided, the log message only is sent to attached client(s).