You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2022/08/14 03:11:09 UTC

[logging-log4cxx] branch LOGCXX-549 created (now 53355a7f)

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

rmiddleton pushed a change to branch LOGCXX-549
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at 53355a7f Optionally configure for networking support or not

This branch includes the following new commits:

     new f503f453 LOGCXX-549 Turned the Socket and SocketServer classes into non APR-specific classes
     new d861ad56 Remove uneeded forward declaration
     new a845d510 Make the datagram socket abstract
     new 53355a7f Optionally configure for networking support or not

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[logging-log4cxx] 03/04: Make the datagram socket abstract

Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a845d5101c74fa28e37f12b6b4b0aabd6751652b
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Aug 13 16:01:16 2022 -0400

    Make the datagram socket abstract
---
 src/main/cpp/CMakeLists.txt                        |   5 +-
 .../{datagramsocket.cpp => aprdatagramsocket.cpp}  | 265 ++++++++-------------
 src/main/cpp/datagramsocket.cpp                    | 224 ++---------------
 src/main/cpp/syslogwriter.cpp                      |   2 +-
 src/main/include/log4cxx/helpers/datagramsocket.h  |  57 +++--
 .../include/log4cxx/private/aprdatagramsocket.h    |  59 +++++
 .../include/log4cxx/private/datagramsocket_priv.h  |  58 +++++
 7 files changed, 275 insertions(+), 395 deletions(-)

diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 0f71bf66..e8f8d905 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -51,8 +51,9 @@ target_sources(log4cxx
   configurator.cpp
   consoleappender.cpp
   cyclicbuffer.cpp
-  datagrampacket.cpp
-  datagramsocket.cpp
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,datagrampacket.cpp,>
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,datagramsocket.cpp,>
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprdatagramsocket.cpp,>
   date.cpp
   dateformat.cpp
   datepatternconverter.cpp
diff --git a/src/main/cpp/datagramsocket.cpp b/src/main/cpp/aprdatagramsocket.cpp
similarity index 53%
copy from src/main/cpp/datagramsocket.cpp
copy to src/main/cpp/aprdatagramsocket.cpp
index 0aa46ff9..3ace8528 100644
--- a/src/main/cpp/datagramsocket.cpp
+++ b/src/main/cpp/aprdatagramsocket.cpp
@@ -14,168 +14,60 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <log4cxx/logstring.h>
-#include <log4cxx/helpers/datagramsocket.h>
-#include <log4cxx/helpers/datagrampacket.h>
-#include <log4cxx/helpers/loglog.h>
-#include <log4cxx/helpers/transcoder.h>
 
-#include "apr_network_io.h"
-#include "apr_lib.h"
+#include <log4cxx/private/aprdatagramsocket.h>
+#include <log4cxx/private/datagramsocket_priv.h>
+#include <apr_network_io.h>
 
-using namespace log4cxx::helpers;
+using log4cxx::helpers::APRDatagramSocket;
 
-struct DatagramSocket::DatagramSocketPriv
-{
-	DatagramSocketPriv()
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
+#define _priv static_cast<APRDatagramSocketPriv*>(m_priv.get())
 
-	DatagramSocketPriv(int localPort1)
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
+struct APRDatagramSocket::APRDatagramSocketPriv : public DatagramSocketPriv {
+	APRDatagramSocketPriv() :
+		DatagramSocketPriv(),
+		socket(nullptr)
+	{}
 
-	DatagramSocketPriv(int localPort1, InetAddressPtr localAddress1)
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
+	APRDatagramSocketPriv(int port) :
+		DatagramSocketPriv(port),
+		socket(nullptr)
+	{}
+
+	APRDatagramSocketPriv(int port, InetAddressPtr localAddress) :
+		DatagramSocketPriv(port, localAddress),
+		socket(nullptr)
+	{}
 
 	/** The APR socket */
 	apr_socket_t* socket;
 
 	/** The memory pool for the socket */
 	Pool socketPool;
-
-	InetAddressPtr address;
-
-	InetAddressPtr localAddress;
-
-	int port;
-
-	/** The local port number to which this socket is connected. */
-	int localPort;
 };
 
-IMPLEMENT_LOG4CXX_OBJECT(DatagramSocket)
-
-DatagramSocket::DatagramSocket()
-	: m_priv(std::make_unique<DatagramSocketPriv>())
-{
-	create();
-}
-
-DatagramSocket::DatagramSocket(int localPort1)
-	: m_priv(std::make_unique<DatagramSocketPriv>(localPort1))
-{
-	InetAddressPtr bindAddr = InetAddress::anyAddress();
-
-	create();
-	bind(localPort1, bindAddr);
-}
-
-DatagramSocket::DatagramSocket(int localPort1, InetAddressPtr localAddress1)
-	: m_priv(std::make_unique<DatagramSocketPriv>(localPort1, localAddress1))
-{
-	create();
-	bind(localPort1, localAddress1);
-}
-
-DatagramSocket::~DatagramSocket()
-{
-	try
-	{
-		close();
-	}
-	catch (SocketException&)
-	{
-	}
-}
-
-/**  Binds a datagram socket to a local port and address.*/
-void DatagramSocket::bind(int localPort1, InetAddressPtr localAddress1)
-{
-	Pool addrPool;
-
-	// Create server socket address (including port number)
-	LOG4CXX_ENCODE_CHAR(hostAddr, localAddress1->getHostAddress());
-	apr_sockaddr_t* server_addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&server_addr, hostAddr.c_str(), APR_INET,
-			localPort1, 0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw BindException(status);
-	}
-
-	// bind the socket to the address
-	status = apr_socket_bind(m_priv->socket, server_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw BindException(status);
-	}
-
-	m_priv->localPort = localPort1;
-	m_priv->localAddress = localAddress1;
+APRDatagramSocket::APRDatagramSocket() :
+	DatagramSocket(std::make_unique<APRDatagramSocketPriv>()){
+	init();
 }
 
-/** Close the socket.*/
-void DatagramSocket::close()
-{
-	if (m_priv->socket != 0)
-	{
-		apr_status_t status = apr_socket_close(m_priv->socket);
-
-		if (status != APR_SUCCESS)
-		{
-			throw SocketException(status);
-		}
-
-		m_priv->socket = 0;
-		m_priv->localPort = 0;
-	}
+APRDatagramSocket::APRDatagramSocket(int port) :
+	DatagramSocket(std::make_unique<APRDatagramSocketPriv>(port)){
+	init();
 }
 
-void DatagramSocket::connect(InetAddressPtr address1, int port1)
-{
-
-	m_priv->address = address1;
-	m_priv->port = port1;
-
-	Pool addrPool;
-
-	// create socket address
-	LOG4CXX_ENCODE_CHAR(hostAddr, address1->getHostAddress());
-	apr_sockaddr_t* client_addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&client_addr, hostAddr.c_str(), APR_INET,
-			m_priv->port, 0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-
-	// connect the socket
-	status = apr_socket_connect(m_priv->socket, client_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
+APRDatagramSocket::APRDatagramSocket(int port, InetAddressPtr laddr) :
+	DatagramSocket(std::make_unique<APRDatagramSocketPriv>(port, laddr)){
+	init();
 }
 
-/** Creates a datagram socket.*/
-void DatagramSocket::create()
+void APRDatagramSocket::init()
 {
 	apr_socket_t* newSocket;
 	apr_status_t status =
 		apr_socket_create(&newSocket, APR_INET, SOCK_DGRAM,
-			APR_PROTO_UDP, m_priv->socketPool.getAPRPool());
-	m_priv->socket = newSocket;
+			APR_PROTO_UDP, _priv->socketPool.getAPRPool());
+	_priv->socket = newSocket;
 
 	if (status != APR_SUCCESS)
 	{
@@ -183,8 +75,7 @@ void DatagramSocket::create()
 	}
 }
 
-/** Receive the datagram packet.*/
-void DatagramSocket::receive(DatagramPacketPtr& p)
+void APRDatagramSocket::receive(DatagramPacketPtr& p)
 {
 	Pool addrPool;
 
@@ -202,7 +93,7 @@ void DatagramSocket::receive(DatagramPacketPtr& p)
 
 	// receive the datagram packet
 	apr_size_t len = p->getLength();
-	status = apr_socket_recvfrom(addr, m_priv->socket, 0,
+	status = apr_socket_recvfrom(addr, _priv->socket, 0,
 			(char*)p->getData(), &len);
 
 	if (status != APR_SUCCESS)
@@ -211,8 +102,7 @@ void DatagramSocket::receive(DatagramPacketPtr& p)
 	}
 }
 
-/**  Sends a datagram packet.*/
-void DatagramSocket::send(DatagramPacketPtr& p)
+void APRDatagramSocket::send(DatagramPacketPtr& p)
 {
 	Pool addrPool;
 
@@ -230,7 +120,7 @@ void DatagramSocket::send(DatagramPacketPtr& p)
 
 	// send the datagram packet
 	apr_size_t len = p->getLength();
-	status = apr_socket_sendto(m_priv->socket, addr, 0,
+	status = apr_socket_sendto(_priv->socket, addr, 0,
 			(char*)p->getData(), &len);
 
 	if (status != APR_SUCCESS)
@@ -239,37 +129,80 @@ void DatagramSocket::send(DatagramPacketPtr& p)
 	}
 }
 
-InetAddressPtr DatagramSocket::getInetAddress() const
-{
-	return m_priv->address;
-}
+void APRDatagramSocket::close(){
+	if (_priv->socket != 0)
+	{
+		apr_status_t status = apr_socket_close(_priv->socket);
 
-InetAddressPtr DatagramSocket::getLocalAddress() const
-{
-	return m_priv->localAddress;
-}
+		if (status != APR_SUCCESS)
+		{
+			throw SocketException(status);
+		}
 
-int DatagramSocket::getLocalPort() const
-{
-	return m_priv->localPort;
+		_priv->socket = 0;
+		_priv->localPort = 0;
+	}
 }
 
-int DatagramSocket::getPort() const
+void APRDatagramSocket::bind(int localPort1, InetAddressPtr localAddress1)
 {
-	return m_priv->port;
-}
+	Pool addrPool;
 
-bool DatagramSocket::isBound() const
-{
-	return m_priv->localPort != 0;
+	// Create server socket address (including port number)
+	LOG4CXX_ENCODE_CHAR(hostAddr, localAddress1->getHostAddress());
+	apr_sockaddr_t* server_addr;
+	apr_status_t status =
+		apr_sockaddr_info_get(&server_addr, hostAddr.c_str(), APR_INET,
+			localPort1, 0, addrPool.getAPRPool());
+
+	if (status != APR_SUCCESS)
+	{
+		throw BindException(status);
+	}
+
+	// bind the socket to the address
+	status = apr_socket_bind(_priv->socket, server_addr);
+
+	if (status != APR_SUCCESS)
+	{
+		throw BindException(status);
+	}
+
+	m_priv->localPort = localPort1;
+	m_priv->localAddress = localAddress1;
 }
 
-bool DatagramSocket::isClosed() const
+
+void APRDatagramSocket::connect(InetAddressPtr address1, int port1)
 {
-	return m_priv->socket != 0;
+	m_priv->address = address1;
+	m_priv->port = port1;
+
+	Pool addrPool;
+
+	// create socket address
+	LOG4CXX_ENCODE_CHAR(hostAddr, address1->getHostAddress());
+	apr_sockaddr_t* client_addr;
+	apr_status_t status =
+		apr_sockaddr_info_get(&client_addr, hostAddr.c_str(), APR_INET,
+			m_priv->port, 0, addrPool.getAPRPool());
+
+	if (status != APR_SUCCESS)
+	{
+		throw ConnectException(status);
+	}
+
+	// connect the socket
+	status = apr_socket_connect(_priv->socket, client_addr);
+
+	if (status != APR_SUCCESS)
+	{
+		throw ConnectException(status);
+	}
 }
 
-bool DatagramSocket::isConnected() const
+
+bool APRDatagramSocket::isClosed() const
 {
-	return m_priv->port != 0;
+	return _priv->socket != nullptr;
 }
diff --git a/src/main/cpp/datagramsocket.cpp b/src/main/cpp/datagramsocket.cpp
index 0aa46ff9..ac71ecbe 100644
--- a/src/main/cpp/datagramsocket.cpp
+++ b/src/main/cpp/datagramsocket.cpp
@@ -19,68 +19,19 @@
 #include <log4cxx/helpers/datagrampacket.h>
 #include <log4cxx/helpers/loglog.h>
 #include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/private/datagramsocket_priv.h>
+#include <log4cxx/private/aprdatagramsocket.h>
 
 #include "apr_network_io.h"
 #include "apr_lib.h"
 
 using namespace log4cxx::helpers;
 
-struct DatagramSocket::DatagramSocketPriv
-{
-	DatagramSocketPriv()
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
-
-	DatagramSocketPriv(int localPort1)
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
-
-	DatagramSocketPriv(int localPort1, InetAddressPtr localAddress1)
-		: socket(0), address(), localAddress(), port(0), localPort(0)
-	{
-	}
-
-	/** The APR socket */
-	apr_socket_t* socket;
-
-	/** The memory pool for the socket */
-	Pool socketPool;
-
-	InetAddressPtr address;
-
-	InetAddressPtr localAddress;
-
-	int port;
-
-	/** The local port number to which this socket is connected. */
-	int localPort;
-};
-
 IMPLEMENT_LOG4CXX_OBJECT(DatagramSocket)
 
-DatagramSocket::DatagramSocket()
-	: m_priv(std::make_unique<DatagramSocketPriv>())
-{
-	create();
-}
-
-DatagramSocket::DatagramSocket(int localPort1)
-	: m_priv(std::make_unique<DatagramSocketPriv>(localPort1))
-{
-	InetAddressPtr bindAddr = InetAddress::anyAddress();
-
-	create();
-	bind(localPort1, bindAddr);
-}
-
-DatagramSocket::DatagramSocket(int localPort1, InetAddressPtr localAddress1)
-	: m_priv(std::make_unique<DatagramSocketPriv>(localPort1, localAddress1))
-{
-	create();
-	bind(localPort1, localAddress1);
-}
+DatagramSocket::DatagramSocket(std::unique_ptr<DatagramSocketPriv> priv) :
+	m_priv(std::move(priv))
+{}
 
 DatagramSocket::~DatagramSocket()
 {
@@ -93,150 +44,9 @@ DatagramSocket::~DatagramSocket()
 	}
 }
 
-/**  Binds a datagram socket to a local port and address.*/
-void DatagramSocket::bind(int localPort1, InetAddressPtr localAddress1)
-{
-	Pool addrPool;
-
-	// Create server socket address (including port number)
-	LOG4CXX_ENCODE_CHAR(hostAddr, localAddress1->getHostAddress());
-	apr_sockaddr_t* server_addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&server_addr, hostAddr.c_str(), APR_INET,
-			localPort1, 0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw BindException(status);
-	}
-
-	// bind the socket to the address
-	status = apr_socket_bind(m_priv->socket, server_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw BindException(status);
-	}
-
-	m_priv->localPort = localPort1;
-	m_priv->localAddress = localAddress1;
-}
-
 /** Close the socket.*/
 void DatagramSocket::close()
 {
-	if (m_priv->socket != 0)
-	{
-		apr_status_t status = apr_socket_close(m_priv->socket);
-
-		if (status != APR_SUCCESS)
-		{
-			throw SocketException(status);
-		}
-
-		m_priv->socket = 0;
-		m_priv->localPort = 0;
-	}
-}
-
-void DatagramSocket::connect(InetAddressPtr address1, int port1)
-{
-
-	m_priv->address = address1;
-	m_priv->port = port1;
-
-	Pool addrPool;
-
-	// create socket address
-	LOG4CXX_ENCODE_CHAR(hostAddr, address1->getHostAddress());
-	apr_sockaddr_t* client_addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&client_addr, hostAddr.c_str(), APR_INET,
-			m_priv->port, 0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-
-	// connect the socket
-	status = apr_socket_connect(m_priv->socket, client_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-}
-
-/** Creates a datagram socket.*/
-void DatagramSocket::create()
-{
-	apr_socket_t* newSocket;
-	apr_status_t status =
-		apr_socket_create(&newSocket, APR_INET, SOCK_DGRAM,
-			APR_PROTO_UDP, m_priv->socketPool.getAPRPool());
-	m_priv->socket = newSocket;
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-}
-
-/** Receive the datagram packet.*/
-void DatagramSocket::receive(DatagramPacketPtr& p)
-{
-	Pool addrPool;
-
-	// Create the address from which to receive the datagram packet
-	LOG4CXX_ENCODE_CHAR(hostAddr, p->getAddress()->getHostAddress());
-	apr_sockaddr_t* addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&addr, hostAddr.c_str(), APR_INET,
-			p->getPort(), 0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	// receive the datagram packet
-	apr_size_t len = p->getLength();
-	status = apr_socket_recvfrom(addr, m_priv->socket, 0,
-			(char*)p->getData(), &len);
-
-	if (status != APR_SUCCESS)
-	{
-		throw IOException(status);
-	}
-}
-
-/**  Sends a datagram packet.*/
-void DatagramSocket::send(DatagramPacketPtr& p)
-{
-	Pool addrPool;
-
-	// create the adress to which to send the datagram packet
-	LOG4CXX_ENCODE_CHAR(hostAddr, p->getAddress()->getHostAddress());
-	apr_sockaddr_t* addr;
-	apr_status_t status =
-		apr_sockaddr_info_get(&addr, hostAddr.c_str(), APR_INET, p->getPort(),
-			0, addrPool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	// send the datagram packet
-	apr_size_t len = p->getLength();
-	status = apr_socket_sendto(m_priv->socket, addr, 0,
-			(char*)p->getData(), &len);
-
-	if (status != APR_SUCCESS)
-	{
-		throw IOException(status);
-	}
 }
 
 InetAddressPtr DatagramSocket::getInetAddress() const
@@ -264,12 +74,26 @@ bool DatagramSocket::isBound() const
 	return m_priv->localPort != 0;
 }
 
-bool DatagramSocket::isClosed() const
-{
-	return m_priv->socket != 0;
-}
-
 bool DatagramSocket::isConnected() const
 {
 	return m_priv->port != 0;
 }
+
+DatagramSocketUniquePtr DatagramSocket::create(){
+	return std::make_unique<APRDatagramSocket>();
+}
+
+DatagramSocketUniquePtr DatagramSocket::create(int localPort1){
+	std::unique_ptr<APRDatagramSocket> sock = std::make_unique<APRDatagramSocket>();
+	InetAddressPtr bindAddr = InetAddress::anyAddress();
+
+	sock->bind(localPort1, bindAddr);
+	return sock;
+}
+
+DatagramSocketUniquePtr DatagramSocket::create(int localPort1, InetAddressPtr localAddress1){
+	std::unique_ptr<APRDatagramSocket> sock = std::make_unique<APRDatagramSocket>();
+
+	sock->bind(localPort1, localAddress1);
+	return sock;
+}
diff --git a/src/main/cpp/syslogwriter.cpp b/src/main/cpp/syslogwriter.cpp
index ad8c92e8..dde4ffa8 100644
--- a/src/main/cpp/syslogwriter.cpp
+++ b/src/main/cpp/syslogwriter.cpp
@@ -54,7 +54,7 @@ SyslogWriter::SyslogWriter(const LogString& syslogHost1, int syslogHostPort1)
 
 	try
 	{
-		m_priv->ds = DatagramSocketPtr(new DatagramSocket());
+		m_priv->ds = DatagramSocket::create();
 	}
 	catch (SocketException& e)
 	{
diff --git a/src/main/include/log4cxx/helpers/datagramsocket.h b/src/main/include/log4cxx/helpers/datagramsocket.h
index 04df8edb..cbfd29d2 100644
--- a/src/main/include/log4cxx/helpers/datagramsocket.h
+++ b/src/main/include/log4cxx/helpers/datagramsocket.h
@@ -27,42 +27,38 @@ namespace log4cxx
 {
 namespace helpers
 {
+
+class DatagramSocket;
+LOG4CXX_PTR_DEF(DatagramSocket);
+LOG4CXX_UNIQUE_PTR_DEF(DatagramSocket);
+
 /** This class represents a socket for sending and receiving
 datagram packets.*/
 class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
 {
+	protected:
+		struct DatagramSocketPriv;
+		std::unique_ptr<DatagramSocketPriv> m_priv;
+
+		DatagramSocket(std::unique_ptr<DatagramSocketPriv> priv);
+
 	public:
 		DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramSocket)
 		BEGIN_LOG4CXX_CAST_MAP()
 		LOG4CXX_CAST_ENTRY(DatagramSocket)
 		END_LOG4CXX_CAST_MAP()
 
-		/** Constructs a datagram socket and binds it to any available port
-		on the local host machine.*/
-		DatagramSocket();
-
-		/** Constructs a datagram socket and binds it to the specified
-		port on the local host machine. */
-		DatagramSocket(int port);
-
-		/**  Creates a datagram socket, bound to the specified local
-		address. */
-		DatagramSocket(int port, InetAddressPtr laddr);
-
 		/** ensure the socket is closed. */
-		~DatagramSocket();
+		virtual ~DatagramSocket();
 
 		/**  Binds a datagram socket to a local port and address.*/
-		void bind(int lport, InetAddressPtr laddress);
-
-		/** Creates a datagram socket.*/
-		void create();
+		virtual void bind(int lport, InetAddressPtr laddress) = 0;
 
 		/** Closes this datagram socket */
-		void close();
+		virtual void close();
 
 		/** Connects the socket to a remote address for this socket. */
-		void connect(InetAddressPtr address, int port);
+		virtual void connect(InetAddressPtr address, int port) = 0;
 
 		/** Returns the address to which this socket is connected. */
 		InetAddressPtr getInetAddress() const;
@@ -81,26 +77,35 @@ class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
 		bool isBound() const;
 
 		/** Returns wether the socket is closed or not. */
-		bool isClosed() const;
+		virtual bool isClosed() const = 0;
 
 		/** Returns the connection state of the socket. */
 		bool isConnected() const;
 
 		/**  Receives a datagram packet from this socket. */
-		void receive(DatagramPacketPtr& p);
+		virtual void receive(DatagramPacketPtr& p) = 0;
 
 		/** Sends a datagram packet from this socket. */
-		void  send(DatagramPacketPtr& p);
+		virtual void  send(DatagramPacketPtr& p) = 0;
+
+		/** Constructs a datagram socket and binds it to any available port
+		on the local host machine.*/
+		static DatagramSocketUniquePtr create();
+
+		/** Constructs a datagram socket and binds it to the specified
+		port on the local host machine. */
+		static DatagramSocketUniquePtr create(int port);
+
+		/**  Creates a datagram socket, bound to the specified local
+		address. */
+		static DatagramSocketUniquePtr create(int port, InetAddressPtr laddr);
 
 	private:
 		DatagramSocket(const DatagramSocket&);
 		DatagramSocket& operator=(const DatagramSocket&);
 
-		struct DatagramSocketPriv;
-		std::unique_ptr<DatagramSocketPriv> m_priv;
-
 };
-LOG4CXX_PTR_DEF(DatagramSocket);
+
 }  // namespace helpers
 } // namespace log4cxx
 
diff --git a/src/main/include/log4cxx/private/aprdatagramsocket.h b/src/main/include/log4cxx/private/aprdatagramsocket.h
new file mode 100644
index 00000000..0f75cd0a
--- /dev/null
+++ b/src/main/include/log4cxx/private/aprdatagramsocket.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef LOG4CXX_HELPERS_APRDATAGRAM_SOCKET_H
+#define LOG4CXX_HELPERS_APRDATAGRAM_SOCKET_H
+
+#include <log4cxx/helpers/datagramsocket.h>
+
+namespace log4cxx
+{
+namespace helpers
+{
+
+class APRDatagramSocket : public DatagramSocket {
+    private:
+        struct APRDatagramSocketPriv;
+
+    public:
+	APRDatagramSocket();
+
+	APRDatagramSocket(int port);
+
+	APRDatagramSocket(int port, InetAddressPtr laddr);
+
+	virtual void bind(int lport, InetAddressPtr laddress);
+
+	virtual void close();
+
+	virtual bool isClosed() const;
+
+	/**  Receives a datagram packet from this socket. */
+	virtual void receive(DatagramPacketPtr& p);
+
+	/** Sends a datagram packet from this socket. */
+	virtual void  send(DatagramPacketPtr& p);
+
+	virtual void connect(InetAddressPtr address, int port);
+
+    private:
+	void init();
+};
+
+}
+}
+
+#endif /* LOG4CXX_HELPERS_APRDATAGRAM_SOCKET_H */
diff --git a/src/main/include/log4cxx/private/datagramsocket_priv.h b/src/main/include/log4cxx/private/datagramsocket_priv.h
new file mode 100644
index 00000000..1b4b4bb9
--- /dev/null
+++ b/src/main/include/log4cxx/private/datagramsocket_priv.h
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LOG4CXX_HELPERS_SOCKET_PRIV_H
+#define LOG4CXX_HELPERS_SOCKET_PRIV_H
+
+#include <log4cxx/helpers/datagramsocket.h>
+
+namespace log4cxx
+{
+namespace helpers
+{
+
+struct DatagramSocket::DatagramSocketPriv
+{
+        DatagramSocketPriv()
+	        : address(), localAddress(), port(0), localPort(0)
+	{
+	}
+
+	DatagramSocketPriv(int localPort1)
+	        : address(), localAddress(), port(0), localPort(0)
+	{
+	}
+
+	DatagramSocketPriv(int localPort1, InetAddressPtr localAddress1)
+	        : address(), localAddress(), port(0), localPort(0)
+	{
+	}
+
+	InetAddressPtr address;
+
+	InetAddressPtr localAddress;
+
+	int port;
+
+	/** The local port number to which this socket is connected. */
+	int localPort;
+};
+
+}
+}
+
+#endif /* LOG4CXX_HELPERS_SOCKET_PRIV_H */


[logging-log4cxx] 04/04: Optionally configure for networking support or not

Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 53355a7f06e2b8f1c7e2e5939a0f4ddb0c5c2635
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Aug 13 23:10:50 2022 -0400

    Optionally configure for networking support or not
---
 CMakeLists.txt                      | 16 +++++++++++++++-
 src/main/cpp/CMakeLists.txt         | 37 +++++++++++++++++++++++--------------
 src/main/cpp/class.cpp              | 14 ++++++--------
 src/main/include/CMakeLists.txt     |  4 ++--
 src/test/cpp/helpers/CMakeLists.txt |  6 +++++-
 src/test/cpp/net/CMakeLists.txt     | 17 +++++++++++------
 6 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2e95bdcd..c386d5cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -242,7 +242,7 @@ message(STATUS "  charset ......................... : ${LOG4CXX_CHARSET}")
 message(STATUS "  Using libESMTP .................. : ${HAS_LIBESMTP}")
 message(STATUS "  ODBC library .................... : ${HAS_ODBC}")
 message(STATUS "  syslog .......................... : ${HAS_SYSLOG}")
-message(STATUS "  Networking support .............. : ${NETWORKING_SUPPORT}")
+message(STATUS "  Networking support .............. : ${LOG4CXX_NETWORKING_SUPPORT}")
 message(STATUS "  Qt support ...................... : ${LOG4CXX_QT_SUPPORT}")
 message(STATUS "C++ version and Boost settings:")
 message(STATUS "  Prefer boost: ................... : ${PREFER_BOOST}")
@@ -258,3 +258,17 @@ message(STATUS "  zip ............................. : ${ZIP_APP}")
 message(STATUS "  sed ............................. : ${SED_APP}")
 message(STATUS "  gzip ............................ : ${GZIP_APP}")
 endif(BUILD_TESTING)
+
+message(STATUS "Available appenders:")
+message(STATUS "  Async Appender .................. : ON")
+message(STATUS "  ODBC Appender ................... : ${HAS_ODBC}")
+message(STATUS "  SMTP Appender ................... : ${HAS_LIBESMTP}")
+message(STATUS "  XMLSocketAppender ............... : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  SocketHubAppender ............... : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  SyslogAppender .................. : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  TelnetAppender .................. : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  NTEventLogAppender .............. : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  OutputDebugStringAppender ....... : ${LOG4CXX_NETWORKING_SUPPORT}")
+message(STATUS "  ConsoleAppender ................. : ON")
+message(STATUS "  FileAppender .................... : ON")
+message(STATUS "  RollingFileAppender ............. : ON")
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index e8f8d905..065a7dee 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -27,6 +27,28 @@ else()
     target_compile_definitions(log4cxx PUBLIC LOG4CXX_STATIC)
 endif()
 add_dependencies(log4cxx configure_log4cxx)
+
+if(LOG4CXX_NETWORKING_SUPPORT)
+    set(networking_classes
+	datagrampacket.cpp
+	datagramsocket.cpp
+	aprdatagramsocket.cpp
+	serversocket.cpp
+	aprserversocket.cpp
+	socket.cpp
+	aprsocket.cpp
+	telnetappender.cpp
+	socketappenderskeleton.cpp
+	sockethubappender.cpp
+	socketoutputstream.cpp
+	xmlsocketappender.cpp
+	syslogwriter.cpp
+	syslogappender.cpp
+	)
+else()
+    set(networking_classes "")
+endif()
+
 target_sources(log4cxx
   PRIVATE
   action.cpp
@@ -51,9 +73,6 @@ target_sources(log4cxx
   configurator.cpp
   consoleappender.cpp
   cyclicbuffer.cpp
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,datagrampacket.cpp,>
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,datagramsocket.cpp,>
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprdatagramsocket.cpp,>
   date.cpp
   dateformat.cpp
   datepatternconverter.cpp
@@ -140,28 +159,18 @@ target_sources(log4cxx
   rollingpolicybase.cpp
   rolloverdescription.cpp
   rootlogger.cpp
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,serversocket.cpp,>
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprserversocket.cpp,>
   shortfilelocationpatternconverter.cpp
   simpledateformat.cpp
   simplelayout.cpp
   sizebasedtriggeringpolicy.cpp
   smtpappender.cpp
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,socket.cpp,>
-  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprsocket.cpp,>
-  socketappenderskeleton.cpp
-  sockethubappender.cpp
-  socketoutputstream.cpp
   strftimedateformat.cpp
   stringhelper.cpp
   stringmatchfilter.cpp
   stringtokenizer.cpp
-  syslogappender.cpp
-  syslogwriter.cpp
   system.cpp
   systemerrwriter.cpp
   systemoutwriter.cpp
-  telnetappender.cpp
   threadlocal.cpp
   threadpatternconverter.cpp
   threadusernamepatternconverter.cpp
@@ -176,8 +185,8 @@ target_sources(log4cxx
   writer.cpp
   writerappender.cpp
   xmllayout.cpp
-  xmlsocketappender.cpp
   zipcompressaction.cpp
+  ${networking_classes}
 )
 set_target_properties(log4cxx PROPERTIES
   VERSION ${LIBLOG4CXX_LIB_VERSION}
diff --git a/src/main/cpp/class.cpp b/src/main/cpp/class.cpp
index b3d8f659..d608a4d1 100644
--- a/src/main/cpp/class.cpp
+++ b/src/main/cpp/class.cpp
@@ -176,14 +176,6 @@ void Class::registerClasses()
 	log4cxx::nt::OutputDebugStringAppender::registerClass();
 #endif
 	SMTPAppender::registerClass();
-#if APR_HAS_THREADS
-	SocketHubAppender::registerClass();
-#endif
-	SyslogAppender::registerClass();
-#if APR_HAS_THREADS
-	TelnetAppender::registerClass();
-#endif
-	XMLSocketAppender::registerClass();
 	HTMLLayout::registerClass();
 	PatternLayout::registerClass();
 	SimpleLayout::registerClass();
@@ -200,5 +192,11 @@ void Class::registerClasses()
 	log4cxx::xml::DOMConfigurator::registerClass();
 	log4cxx::PropertyConfigurator::registerClass();
 	log4cxx::varia::FallbackErrorHandler::registerClass();
+#if LOG4CXX_HAS_NETWORKING
+	TelnetAppender::registerClass();
+	XMLSocketAppender::registerClass();
+	SocketHubAppender::registerClass();
+	SyslogAppender::registerClass();
+#endif
 }
 
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index 576701f7..d21ecdac 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -58,8 +58,8 @@ foreach(varName WCHAR_T  UNICHAR  CFSTRING )
   endif()
 endforeach()
 
-option(NETWORKING_SUPPORT "Support logging over a network socket" ON)
-if(NETWORKING_SUPPORT)
+option(LOG4CXX_NETWORKING_SUPPORT "Support logging over a network socket" ON)
+if(LOG4CXX_NETWORKING_SUPPORT)
     set(NETWORKING_SUPPORT 1)
 else()
     set(NETWORKING_SUPPORT 0)
diff --git a/src/test/cpp/helpers/CMakeLists.txt b/src/test/cpp/helpers/CMakeLists.txt
index e8921c81..fe07d973 100644
--- a/src/test/cpp/helpers/CMakeLists.txt
+++ b/src/test/cpp/helpers/CMakeLists.txt
@@ -32,11 +32,15 @@ set(HELPER_TESTS
     relativetimedateformattestcase
     stringhelpertestcase
     stringtokenizertestcase
-    syslogwritertest
     timezonetestcase
     transcodertestcase
     threadutilitytestcase
 )
+
+if(LOG4CXX_NETWORKING_SUPPORT)
+    list(APPEND HELPER_TESTS syslogwritertest)
+endif()
+
 foreach(fileName IN LISTS HELPER_TESTS)
     add_executable(${fileName} "${fileName}.cpp")
     target_compile_definitions(${fileName} PRIVATE ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
diff --git a/src/test/cpp/net/CMakeLists.txt b/src/test/cpp/net/CMakeLists.txt
index 32d3053f..d692f5ef 100644
--- a/src/test/cpp/net/CMakeLists.txt
+++ b/src/test/cpp/net/CMakeLists.txt
@@ -16,12 +16,17 @@
 #
 
 # Tests defined in this directory
-set(NET_TESTS
-    sockethubappendertestcase
-    syslogappendertestcase
-    telnetappendertestcase
-    xmlsocketappendertestcase
-)
+if(LOG4CXX_NETWORKING_SUPPORT)
+    set(NET_TESTS
+	sockethubappendertestcase
+	syslogappendertestcase
+	telnetappendertestcase
+	xmlsocketappendertestcase
+    )
+else()
+    set(NET_TESTS "")
+endif()
+
 if(HAS_LIBESMPT)
     list(APPEND NET_TESTS smtpappendertestcase)
 endif(HAS_LIBESMPT)


[logging-log4cxx] 01/04: LOGCXX-549 Turned the Socket and SocketServer classes into non APR-specific classes

Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f503f453cad66c8bc23ceccdf44b49527de47867
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Aug 13 15:14:01 2022 -0400

    LOGCXX-549 Turned the Socket and SocketServer classes into non APR-specific classes
---
 CMakeLists.txt                                     |   1 +
 src/main/cpp/CMakeLists.txt                        |   6 +-
 .../cpp/{serversocket.cpp => aprserversocket.cpp}  |  80 ++++++------
 src/main/cpp/{socket.cpp => aprsocket.cpp}         |  82 ++++++-------
 src/main/cpp/serversocket.cpp                      | 135 ++-------------------
 src/main/cpp/socket.cpp                            | 129 ++------------------
 src/main/cpp/socketappenderskeleton.cpp            |   4 +-
 src/main/cpp/sockethubappender.cpp                 |   7 +-
 src/main/cpp/telnetappender.cpp                    |   2 +-
 src/main/include/CMakeLists.txt                    |   6 +
 src/main/include/log4cxx/helpers/serversocket.h    |  27 +++--
 src/main/include/log4cxx/helpers/socket.h          |  44 +++----
 src/main/include/log4cxx/log4cxx.h.in              |   3 +-
 .../serversocket.h => private/aprserversocket.h}   |  51 +++-----
 .../serversocket.h => private/aprsocket.h}         |  49 +++-----
 .../serversocket.h => private/serversocket_priv.h} |  48 ++------
 .../serversocket.h => private/socket_priv.h}       |  48 ++------
 17 files changed, 204 insertions(+), 518 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4b96376..2e95bdcd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -242,6 +242,7 @@ message(STATUS "  charset ......................... : ${LOG4CXX_CHARSET}")
 message(STATUS "  Using libESMTP .................. : ${HAS_LIBESMTP}")
 message(STATUS "  ODBC library .................... : ${HAS_ODBC}")
 message(STATUS "  syslog .......................... : ${HAS_SYSLOG}")
+message(STATUS "  Networking support .............. : ${NETWORKING_SUPPORT}")
 message(STATUS "  Qt support ...................... : ${LOG4CXX_QT_SUPPORT}")
 message(STATUS "C++ version and Boost settings:")
 message(STATUS "  Prefer boost: ................... : ${PREFER_BOOST}")
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 8f9c16d5..0f71bf66 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -139,13 +139,15 @@ target_sources(log4cxx
   rollingpolicybase.cpp
   rolloverdescription.cpp
   rootlogger.cpp
-  serversocket.cpp
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,serversocket.cpp,>
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprserversocket.cpp,>
   shortfilelocationpatternconverter.cpp
   simpledateformat.cpp
   simplelayout.cpp
   sizebasedtriggeringpolicy.cpp
   smtpappender.cpp
-  socket.cpp
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,socket.cpp,>
+  $<IF:$<BOOL:NETWORKING_SUPPORT>,aprsocket.cpp,>
   socketappenderskeleton.cpp
   sockethubappender.cpp
   socketoutputstream.cpp
diff --git a/src/main/cpp/serversocket.cpp b/src/main/cpp/aprserversocket.cpp
similarity index 64%
copy from src/main/cpp/serversocket.cpp
copy to src/main/cpp/aprserversocket.cpp
index 1cc9a3b9..797b5a1b 100644
--- a/src/main/cpp/serversocket.cpp
+++ b/src/main/cpp/aprserversocket.cpp
@@ -15,28 +15,35 @@
  * limitations under the License.
  */
 
-#include <log4cxx/helpers/serversocket.h>
-#include <mutex>
+#include <log4cxx/private/aprserversocket.h>
+#include <log4cxx/private/serversocket_priv.h>
+#include <log4cxx/private/aprsocket.h>
 #include "apr_network_io.h"
 #include "apr_pools.h"
 #include "apr_poll.h"
 
-using namespace log4cxx::helpers;
+using log4cxx::helpers::APRServerSocket;
 
-/**  Creates a server socket on a specified port.
-*/
-ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
-{
+#define _priv static_cast<APRServerSocketPriv*>(m_priv.get())
+
+struct APRServerSocket::APRServerSocketPriv : public ServerSocketPrivate {
+	Pool pool;
+	std::mutex mutex;
+	apr_socket_t* socket;
+};
+
+APRServerSocket::APRServerSocket(int port) :
+	ServerSocket(std::make_unique<APRServerSocketPriv>()){
 	apr_status_t status =
-		apr_socket_create(&socket, APR_INET, SOCK_STREAM,
-			APR_PROTO_TCP, pool.getAPRPool());
+		apr_socket_create(&_priv->socket, APR_INET, SOCK_STREAM,
+			APR_PROTO_TCP, _priv->pool.getAPRPool());
 
 	if (status != APR_SUCCESS)
 	{
 		throw SocketException(status);
 	}
 
-	status = apr_socket_opt_set(socket, APR_SO_NONBLOCK, 1);
+	status = apr_socket_opt_set(_priv->socket, APR_SO_NONBLOCK, 1);
 
 	if (status != APR_SUCCESS)
 	{
@@ -47,7 +54,7 @@ ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
 	apr_sockaddr_t* server_addr;
 	status =
 		apr_sockaddr_info_get(&server_addr, NULL, APR_INET,
-			port, 0, pool.getAPRPool());
+			port, 0, _priv->pool.getAPRPool());
 
 	if (status != APR_SUCCESS)
 	{
@@ -55,7 +62,7 @@ ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
 	}
 
 	// bind the socket to the address
-	status = apr_socket_bind(socket, server_addr);
+	status = apr_socket_bind(_priv->socket, server_addr);
 
 	if (status != APR_SUCCESS)
 	{
@@ -63,7 +70,7 @@ ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
 	}
 
 
-	status = apr_socket_listen(socket, 50);
+	status = apr_socket_listen(_priv->socket, 50);
 
 	if (status != APR_SUCCESS)
 	{
@@ -71,50 +78,45 @@ ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
 	}
 }
 
+void APRServerSocket::close(){
+	std::unique_lock<std::mutex> lock(_priv->mutex);
 
-ServerSocket::~ServerSocket()
-{
-}
-
-void ServerSocket::close()
-{
-	std::unique_lock<std::mutex> lock(mutex);
-
-	if (socket != 0)
+	if (_priv->socket != 0)
 	{
-		apr_status_t status = apr_socket_close(socket);
+		apr_status_t status = apr_socket_close(_priv->socket);
 
 		if (status != APR_SUCCESS)
 		{
 			throw SocketException(status);
 		}
 
-		socket = 0;
+		_priv->socket = 0;
 	}
 }
 
+
 /** Listens for a connection to be made to this socket and
 accepts it
 */
-SocketPtr ServerSocket::accept()
+log4cxx::helpers::SocketPtr APRServerSocket::accept()
 {
-	std::unique_lock<std::mutex> lock(mutex);
+	std::unique_lock<std::mutex> lock(_priv->mutex);
 
-	if (socket == 0)
+	if (_priv->socket == 0)
 	{
 		throw IOException();
 	}
 
 	apr_pollfd_t poll;
-	poll.p = pool.getAPRPool();
+	poll.p = _priv->pool.getAPRPool();
 	poll.desc_type = APR_POLL_SOCKET;
 	poll.reqevents = APR_POLLIN;
 	poll.rtnevents = 0;
-	poll.desc.s = socket;
+	poll.desc.s = _priv->socket;
 	poll.client_data = NULL;
 
 	apr_int32_t signaled;
-	apr_interval_time_t to = timeout * 1000;
+	apr_interval_time_t to = _priv->timeout * 1000;
 	apr_status_t status = apr_poll(&poll, 1, &signaled, to);
 
 	if (APR_STATUS_IS_TIMEUP(status))
@@ -135,7 +137,7 @@ SocketPtr ServerSocket::accept()
 	}
 
 	apr_socket_t* newSocket;
-	status = apr_socket_accept(&newSocket, socket, newPool);
+	status = apr_socket_accept(&newSocket, _priv->socket, newPool);
 
 	if (status != APR_SUCCESS)
 	{
@@ -151,19 +153,5 @@ SocketPtr ServerSocket::accept()
 		throw SocketException(status);
 	}
 
-	return SocketPtr(new Socket(newSocket, newPool));
-}
-
-/** Retrive setting for SO_TIMEOUT.
-*/
-int ServerSocket::getSoTimeout() const
-{
-	return timeout;
-}
-
-/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
-*/
-void ServerSocket::setSoTimeout(int newVal)
-{
-	timeout = newVal;
+	return std::make_shared<APRSocket>(newSocket, newPool);
 }
diff --git a/src/main/cpp/socket.cpp b/src/main/cpp/aprsocket.cpp
similarity index 64%
copy from src/main/cpp/socket.cpp
copy to src/main/cpp/aprsocket.cpp
index cdd8724f..fa56fe91 100644
--- a/src/main/cpp/socket.cpp
+++ b/src/main/cpp/aprsocket.cpp
@@ -14,39 +14,50 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <log4cxx/helpers/socket.h>
+
+#include <log4cxx/private/aprsocket.h>
+#include <log4cxx/private/socket_priv.h>
 #include <log4cxx/helpers/bytebuffer.h>
-#include <log4cxx/helpers/transcoder.h>
+
 #include "apr_network_io.h"
 #include "apr_signal.h"
 
+using log4cxx::helpers::APRSocket;
 
-using namespace log4cxx;
-using namespace log4cxx::helpers;
+struct APRSocket::APRSocketPriv : public log4cxx::helpers::Socket::SocketPrivate {
+	APRSocketPriv() :
+		socket(nullptr)
+	{}
 
-IMPLEMENT_LOG4CXX_OBJECT(Socket)
+	APRSocketPriv(apr_socket_t* sock, apr_pool_t* p) :
+		pool(p, true),
+		socket(sock)
+	{}
 
-/** Creates a stream socket and connects it to the specified port
-number at the specified IP address.
-*/
-Socket::Socket(InetAddressPtr& addr, int prt) : pool(), socket(0), address(addr), port(prt)
-{
+	Pool pool;
+	apr_socket_t* socket;
+};
+
+#define _priv static_cast<APRSocketPriv*>(m_priv.get())
+
+APRSocket::APRSocket(InetAddressPtr& address, int port) :
+	Socket(std::make_unique<APRSocketPriv>()){
 	apr_status_t status =
-		apr_socket_create(&socket, APR_INET, SOCK_STREAM,
-			APR_PROTO_TCP, pool.getAPRPool());
+		apr_socket_create(&_priv->socket, APR_INET, SOCK_STREAM,
+			APR_PROTO_TCP, _priv->pool.getAPRPool());
 
 	if (status != APR_SUCCESS)
 	{
 		throw SocketException(status);
 	}
 
-	LOG4CXX_ENCODE_CHAR(host, addr->getHostAddress());
+	LOG4CXX_ENCODE_CHAR(host, address->getHostAddress());
 
 	// create socket address (including port)
 	apr_sockaddr_t* client_addr;
 	status =
 		apr_sockaddr_info_get(&client_addr, host.c_str(), APR_INET,
-			prt, 0, pool.getAPRPool());
+			port, 0, _priv->pool.getAPRPool());
 
 	if (status != APR_SUCCESS)
 	{
@@ -54,7 +65,7 @@ Socket::Socket(InetAddressPtr& addr, int prt) : pool(), socket(0), address(addr)
 	}
 
 	// connect the socket
-	status =  apr_socket_connect(socket, client_addr);
+	status =  apr_socket_connect(_priv->socket, client_addr);
 
 	if (status != APR_SUCCESS)
 	{
@@ -62,15 +73,14 @@ Socket::Socket(InetAddressPtr& addr, int prt) : pool(), socket(0), address(addr)
 	}
 }
 
-Socket::Socket(apr_socket_t* s, apr_pool_t* p) :
-	pool(p, true), socket(s)
-{
+APRSocket::APRSocket(apr_socket_t* s, apr_pool_t* pool) :
+	Socket(std::make_unique<APRSocketPriv>(s, pool)){
 	apr_sockaddr_t* sa;
 	apr_status_t status = apr_socket_addr_get(&sa, APR_REMOTE, s);
 
 	if (status == APR_SUCCESS)
 	{
-		port = sa->port;
+		_priv->port = sa->port;
 		LogString remotename;
 		LogString remoteip;
 
@@ -87,17 +97,13 @@ Socket::Socket(apr_socket_t* s, apr_pool_t* p) :
 			Transcoder::decode(buf, remoteip);
 		}
 
-		address = InetAddressPtr(new InetAddress(remotename, remoteip));
+		_priv->address = InetAddressPtr(new InetAddress(remotename, remoteip));
 	}
 }
 
-Socket::~Socket()
-{
-}
-
-size_t Socket::write(ByteBuffer& buf)
+size_t APRSocket::write(ByteBuffer& buf)
 {
-	if (socket == 0)
+	if (_priv->socket == 0)
 	{
 		throw ClosedChannelException();
 	}
@@ -114,10 +120,10 @@ size_t Socket::write(ByteBuffer& buf)
 		// SIGPIPE handler.
 #if APR_HAVE_SIGACTION
 		apr_sigfunc_t* old = apr_signal(SIGPIPE, SIG_IGN);
-		apr_status_t status = apr_socket_send(socket, buf.current(), &written);
+		apr_status_t status = apr_socket_send(_priv->socket, buf.current(), &written);
 		apr_signal(SIGPIPE, old);
 #else
-		apr_status_t status = apr_socket_send(socket, buf.current(), &written);
+		apr_status_t status = apr_socket_send(_priv->socket, buf.current(), &written);
 #endif
 
 		buf.position(buf.position() + written);
@@ -133,29 +139,17 @@ size_t Socket::write(ByteBuffer& buf)
 }
 
 
-void Socket::close()
+void APRSocket::close()
 {
-	if (socket != 0)
+	if (_priv->socket != 0)
 	{
-		apr_status_t status = apr_socket_close(socket);
+		apr_status_t status = apr_socket_close(_priv->socket);
 
 		if (status != APR_SUCCESS)
 		{
 			throw SocketException(status);
 		}
 
-		socket = 0;
+		_priv->socket = 0;
 	}
 }
-
-InetAddressPtr Socket::getInetAddress() const
-{
-	return address;
-}
-
-int Socket::getPort() const
-{
-	return port;
-}
-
-
diff --git a/src/main/cpp/serversocket.cpp b/src/main/cpp/serversocket.cpp
index 1cc9a3b9..cb81a141 100644
--- a/src/main/cpp/serversocket.cpp
+++ b/src/main/cpp/serversocket.cpp
@@ -16,154 +16,41 @@
  */
 
 #include <log4cxx/helpers/serversocket.h>
-#include <mutex>
-#include "apr_network_io.h"
-#include "apr_pools.h"
-#include "apr_poll.h"
+#include <log4cxx/private/serversocket_priv.h>
+#include <log4cxx/private/aprserversocket.h>
 
 using namespace log4cxx::helpers;
 
 /**  Creates a server socket on a specified port.
 */
-ServerSocket::ServerSocket(int port) : pool(), socket(0), timeout(0)
+ServerSocket::ServerSocket(std::unique_ptr<ServerSocketPrivate> priv) :
+	m_priv(std::move(priv))
 {
-	apr_status_t status =
-		apr_socket_create(&socket, APR_INET, SOCK_STREAM,
-			APR_PROTO_TCP, pool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	status = apr_socket_opt_set(socket, APR_SO_NONBLOCK, 1);
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	// Create server socket address (including port number)
-	apr_sockaddr_t* server_addr;
-	status =
-		apr_sockaddr_info_get(&server_addr, NULL, APR_INET,
-			port, 0, pool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-
-	// bind the socket to the address
-	status = apr_socket_bind(socket, server_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw BindException(status);
-	}
-
-
-	status = apr_socket_listen(socket, 50);
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
 }
 
-
 ServerSocket::~ServerSocket()
 {
+	close();
 }
 
 void ServerSocket::close()
 {
-	std::unique_lock<std::mutex> lock(mutex);
-
-	if (socket != 0)
-	{
-		apr_status_t status = apr_socket_close(socket);
-
-		if (status != APR_SUCCESS)
-		{
-			throw SocketException(status);
-		}
-
-		socket = 0;
-	}
-}
-
-/** Listens for a connection to be made to this socket and
-accepts it
-*/
-SocketPtr ServerSocket::accept()
-{
-	std::unique_lock<std::mutex> lock(mutex);
-
-	if (socket == 0)
-	{
-		throw IOException();
-	}
-
-	apr_pollfd_t poll;
-	poll.p = pool.getAPRPool();
-	poll.desc_type = APR_POLL_SOCKET;
-	poll.reqevents = APR_POLLIN;
-	poll.rtnevents = 0;
-	poll.desc.s = socket;
-	poll.client_data = NULL;
-
-	apr_int32_t signaled;
-	apr_interval_time_t to = timeout * 1000;
-	apr_status_t status = apr_poll(&poll, 1, &signaled, to);
-
-	if (APR_STATUS_IS_TIMEUP(status))
-	{
-		throw SocketTimeoutException();
-	}
-	else if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	apr_pool_t* newPool;
-	status = apr_pool_create(&newPool, 0);
-
-	if (status != APR_SUCCESS)
-	{
-		throw PoolException(status);
-	}
-
-	apr_socket_t* newSocket;
-	status = apr_socket_accept(&newSocket, socket, newPool);
-
-	if (status != APR_SUCCESS)
-	{
-		apr_pool_destroy(newPool);
-		throw SocketException(status);
-	}
-
-	status = apr_socket_opt_set(newSocket, APR_SO_NONBLOCK, 0);
-
-	if (status != APR_SUCCESS)
-	{
-		apr_pool_destroy(newPool);
-		throw SocketException(status);
-	}
-
-	return SocketPtr(new Socket(newSocket, newPool));
 }
 
 /** Retrive setting for SO_TIMEOUT.
 */
 int ServerSocket::getSoTimeout() const
 {
-	return timeout;
+	return m_priv->timeout;
 }
 
 /** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
 */
 void ServerSocket::setSoTimeout(int newVal)
 {
-	timeout = newVal;
+	m_priv->timeout = newVal;
+}
+
+ServerSocketUniquePtr ServerSocket::create(int port){
+	return std::make_unique<APRServerSocket>(port);
 }
diff --git a/src/main/cpp/socket.cpp b/src/main/cpp/socket.cpp
index cdd8724f..d27e4924 100644
--- a/src/main/cpp/socket.cpp
+++ b/src/main/cpp/socket.cpp
@@ -17,145 +17,36 @@
 #include <log4cxx/helpers/socket.h>
 #include <log4cxx/helpers/bytebuffer.h>
 #include <log4cxx/helpers/transcoder.h>
-#include "apr_network_io.h"
-#include "apr_signal.h"
 
+#include <log4cxx/private/socket_priv.h>
+#include <log4cxx/private/aprsocket.h>
 
 using namespace log4cxx;
 using namespace log4cxx::helpers;
 
 IMPLEMENT_LOG4CXX_OBJECT(Socket)
 
-/** Creates a stream socket and connects it to the specified port
-number at the specified IP address.
-*/
-Socket::Socket(InetAddressPtr& addr, int prt) : pool(), socket(0), address(addr), port(prt)
-{
-	apr_status_t status =
-		apr_socket_create(&socket, APR_INET, SOCK_STREAM,
-			APR_PROTO_TCP, pool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw SocketException(status);
-	}
-
-	LOG4CXX_ENCODE_CHAR(host, addr->getHostAddress());
-
-	// create socket address (including port)
-	apr_sockaddr_t* client_addr;
-	status =
-		apr_sockaddr_info_get(&client_addr, host.c_str(), APR_INET,
-			prt, 0, pool.getAPRPool());
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-
-	// connect the socket
-	status =  apr_socket_connect(socket, client_addr);
-
-	if (status != APR_SUCCESS)
-	{
-		throw ConnectException(status);
-	}
-}
+Socket::Socket(std::unique_ptr<Socket::SocketPrivate> priv) :
+	m_priv(std::move(priv)){
 
-Socket::Socket(apr_socket_t* s, apr_pool_t* p) :
-	pool(p, true), socket(s)
-{
-	apr_sockaddr_t* sa;
-	apr_status_t status = apr_socket_addr_get(&sa, APR_REMOTE, s);
-
-	if (status == APR_SUCCESS)
-	{
-		port = sa->port;
-		LogString remotename;
-		LogString remoteip;
-
-		if (sa->hostname != NULL)
-		{
-			Transcoder::decode(sa->hostname, remotename);
-		}
-
-		char* buf = 0;
-		status = apr_sockaddr_ip_get(&buf, sa);
-
-		if (status == APR_SUCCESS)
-		{
-			Transcoder::decode(buf, remoteip);
-		}
-
-		address = InetAddressPtr(new InetAddress(remotename, remoteip));
-	}
 }
 
 Socket::~Socket()
 {
 }
 
-size_t Socket::write(ByteBuffer& buf)
-{
-	if (socket == 0)
-	{
-		throw ClosedChannelException();
-	}
-
-	int totalWritten = 0;
-
-	while (buf.remaining() > 0)
-	{
-		apr_size_t written = buf.remaining();
-
-		// while writing to the socket, we need to ignore the SIGPIPE
-		// signal. Otherwise, when the client has closed the connection,
-		// the send() function would not return an error but call the
-		// SIGPIPE handler.
-#if APR_HAVE_SIGACTION
-		apr_sigfunc_t* old = apr_signal(SIGPIPE, SIG_IGN);
-		apr_status_t status = apr_socket_send(socket, buf.current(), &written);
-		apr_signal(SIGPIPE, old);
-#else
-		apr_status_t status = apr_socket_send(socket, buf.current(), &written);
-#endif
-
-		buf.position(buf.position() + written);
-		totalWritten += written;
-
-		if (status != APR_SUCCESS)
-		{
-			throw SocketException(status);
-		}
-	}
-
-	return totalWritten;
-}
-
-
-void Socket::close()
-{
-	if (socket != 0)
-	{
-		apr_status_t status = apr_socket_close(socket);
-
-		if (status != APR_SUCCESS)
-		{
-			throw SocketException(status);
-		}
-
-		socket = 0;
-	}
-}
-
 InetAddressPtr Socket::getInetAddress() const
 {
-	return address;
+	return m_priv->address;
 }
 
 int Socket::getPort() const
 {
-	return port;
+	return m_priv->port;
+}
+
+SocketUniquePtr Socket::create(InetAddressPtr& address, int port){
+	return std::make_unique<APRSocket>(address, port);
 }
 
 
diff --git a/src/main/cpp/socketappenderskeleton.cpp b/src/main/cpp/socketappenderskeleton.cpp
index de79bd8a..03d87cc1 100644
--- a/src/main/cpp/socketappenderskeleton.cpp
+++ b/src/main/cpp/socketappenderskeleton.cpp
@@ -89,7 +89,7 @@ void SocketAppenderSkeleton::connect(Pool& p)
 
 		try
 		{
-			SocketPtr socket(new Socket(_priv->address, _priv->port));
+			SocketPtr socket = Socket::create(_priv->address, _priv->port);
 			setSocket(socket, p);
 		}
 		catch (SocketException& e)
@@ -157,7 +157,7 @@ void SocketAppenderSkeleton::monitor()
 			{
 				LogLog::debug(LogString(LOG4CXX_STR("Attempting connection to "))
 					+ _priv->address->getHostName());
-				socket = SocketPtr(new Socket(_priv->address, _priv->port));
+				socket = Socket::create(_priv->address, _priv->port);
 				Pool p;
 				setSocket(socket, p);
 				LogLog::debug(LOG4CXX_STR("Connection established. Exiting connector thread."));
diff --git a/src/main/cpp/sockethubappender.cpp b/src/main/cpp/sockethubappender.cpp
index 86613bbe..ca84f168 100644
--- a/src/main/cpp/sockethubappender.cpp
+++ b/src/main/cpp/sockethubappender.cpp
@@ -201,17 +201,16 @@ void SocketHubAppender::startServer()
 
 void SocketHubAppender::monitor()
 {
-	ServerSocket* serverSocket = 0;
+	ServerSocketUniquePtr serverSocket = 0;
 
 	try
 	{
-		serverSocket = new ServerSocket(_priv->port);
+		serverSocket = ServerSocket::create(_priv->port);
 		serverSocket->setSoTimeout(1000);
 	}
 	catch (SocketException& e)
 	{
 		LogLog::error(LOG4CXX_STR("exception setting timeout, shutting down server socket."), e);
-		delete serverSocket;
 		return;
 	}
 
@@ -266,8 +265,6 @@ void SocketHubAppender::monitor()
 
 		stopRunning = (stopRunning || _priv->closed);
 	}
-
-	delete serverSocket;
 }
 
 void SocketHubAppender::setPort(int port1)
diff --git a/src/main/cpp/telnetappender.cpp b/src/main/cpp/telnetappender.cpp
index 9a2e8ee5..0c72a809 100644
--- a/src/main/cpp/telnetappender.cpp
+++ b/src/main/cpp/telnetappender.cpp
@@ -75,7 +75,7 @@ void TelnetAppender::activateOptions(Pool& /* p */)
 {
 	if (_priv->serverSocket == NULL)
 	{
-		_priv->serverSocket = std::make_unique<ServerSocket>(_priv->port);
+		_priv->serverSocket = ServerSocket::create(_priv->port);
 		_priv->serverSocket->setSoTimeout(1000);
 	}
 
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index e31443fb..576701f7 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -58,6 +58,12 @@ foreach(varName WCHAR_T  UNICHAR  CFSTRING )
   endif()
 endforeach()
 
+option(NETWORKING_SUPPORT "Support logging over a network socket" ON)
+if(NETWORKING_SUPPORT)
+    set(NETWORKING_SUPPORT 1)
+else()
+    set(NETWORKING_SUPPORT 0)
+endif()
 
 # Configure log4cxx_private.h
 set(LOG4CXX_CHARSET "locale" CACHE STRING "LogString characters, choice of locale (default), utf-8, ISO-8859-1, US-ASCII, EBCDIC")
diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/helpers/serversocket.h
index 7da75b96..b6cc51d7 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/helpers/serversocket.h
@@ -21,27 +21,35 @@
 #include <log4cxx/helpers/socket.h>
 #include <mutex>
 
+struct apr_socket_t;
+
 namespace log4cxx
 {
 namespace helpers
 {
+
+class ServerSocket;
+LOG4CXX_PTR_DEF(ServerSocket);
+LOG4CXX_UNIQUE_PTR_DEF(ServerSocket);
+
 class LOG4CXX_EXPORT ServerSocket
 {
+	protected:
+		struct ServerSocketPrivate;
+		ServerSocket(std::unique_ptr<ServerSocketPrivate> priv);
+
 	public:
-		/**  Creates a server socket on a specified port.
-		*/
-		ServerSocket(int port);
 
 		virtual ~ServerSocket();
 
 		/** Listens for a connection to be made to this socket and
 		accepts it
 		*/
-		SocketPtr accept();
+		virtual SocketPtr accept() = 0;
 
 		/** Closes this socket.
 		*/
-		void close();
+		virtual void close();
 
 		/** Retrive setting for SO_TIMEOUT.
 		*/
@@ -51,11 +59,10 @@ class LOG4CXX_EXPORT ServerSocket
 		*/
 		void setSoTimeout(int timeout);
 
-	private:
-		Pool pool;
-		std::mutex mutex;
-		apr_socket_t* socket;
-		int timeout;
+		static ServerSocketUniquePtr create(int port);
+
+	protected:
+		std::unique_ptr<ServerSocketPrivate> m_priv;
 
 };
 }  // namespace helpers
diff --git a/src/main/include/log4cxx/helpers/socket.h b/src/main/include/log4cxx/helpers/socket.h
index 9284490b..fd7cadd4 100644
--- a/src/main/include/log4cxx/helpers/socket.h
+++ b/src/main/include/log4cxx/helpers/socket.h
@@ -18,11 +18,6 @@
 #ifndef _LOG4CXX_HELPERS_SOCKET_H
 #define _LOG4CXX_HELPERS_SOCKET_H
 
-extern "C" {
-	struct apr_socket_t;
-}
-
-
 #include <log4cxx/helpers/inetaddress.h>
 #include <log4cxx/helpers/pool.h>
 
@@ -32,6 +27,11 @@ namespace log4cxx
 namespace helpers
 {
 class ByteBuffer;
+
+class Socket;
+LOG4CXX_PTR_DEF(Socket);
+LOG4CXX_UNIQUE_PTR_DEF(Socket);
+
 /**
 <p>This class implements client sockets (also called just "sockets"). A socket
 is an endpoint for communication between two machines.
@@ -42,48 +42,40 @@ local firewall.
 */
 class LOG4CXX_EXPORT Socket : public helpers::Object
 {
+	protected:
+		struct SocketPrivate;
+
+		Socket(std::unique_ptr<SocketPrivate>);
+
 	public:
 		DECLARE_ABSTRACT_LOG4CXX_OBJECT(Socket)
 		BEGIN_LOG4CXX_CAST_MAP()
 		LOG4CXX_CAST_ENTRY(Socket)
 		END_LOG4CXX_CAST_MAP()
 
-		/** Creates a stream socket and connects it to the specified port
-		number at the specified IP address.
-		*/
-		Socket(InetAddressPtr& address, int port);
-		Socket(apr_socket_t* socket, apr_pool_t* pool);
-		~Socket();
+		virtual ~Socket();
 
-		size_t write(ByteBuffer&);
+		virtual size_t write(ByteBuffer&) = 0;
 
 		/** Closes this socket. */
-		void close();
+		virtual void close() = 0;
 
 		/** Returns the value of this socket's address field. */
 		InetAddressPtr getInetAddress() const;
 
 		/** Returns the value of this socket's port field. */
 		int getPort() const;
+
+		static SocketUniquePtr create(InetAddressPtr& address, int port);
+
 	private:
 		Socket(const Socket&);
 		Socket& operator=(const Socket&);
 
-		Pool pool;
-
-		apr_socket_t* socket;
-
-
-		/** The IP address of the remote end of this socket. */
-		InetAddressPtr address;
-
-		/** The port number on the remote host to which
-		this socket is connected. */
-		int port;
+	protected:
+		std::unique_ptr<SocketPrivate> m_priv;
 };
 
-LOG4CXX_PTR_DEF(Socket);
-
 } // namespace helpers
 } // namespace log4cxx
 
diff --git a/src/main/include/log4cxx/log4cxx.h.in b/src/main/include/log4cxx/log4cxx.h.in
index c97869cc..e350d831 100644
--- a/src/main/include/log4cxx/log4cxx.h.in
+++ b/src/main/include/log4cxx/log4cxx.h.in
@@ -48,7 +48,7 @@
 #define LOG4CXX_WCHAR_T_API @WCHAR_T_API@
 #define LOG4CXX_UNICHAR_API @UNICHAR_API@
 #define LOG4CXX_CFSTRING_API @CFSTRING_API@
-
+#define LOG4CXX_HAS_NETWORKING @NETWORKING_SUPPORT@
 
 typedef long long log4cxx_int64_t;
 #define LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE 0
@@ -62,6 +62,7 @@ typedef unsigned int log4cxx_uint32_t;
 
 #define LOG4CXX_PTR_DEF(T) typedef std::shared_ptr<T> T##Ptr;\
 	typedef std::weak_ptr<T> T##WeakPtr
+#define LOG4CXX_UNIQUE_PTR_DEF(T) typedef std::unique_ptr<T> T##UniquePtr;
 #define LOG4CXX_LIST_DEF(N, T) typedef std::vector<T> N
 
 #if _WIN32
diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/private/aprserversocket.h
similarity index 52%
copy from src/main/include/log4cxx/helpers/serversocket.h
copy to src/main/include/log4cxx/private/aprserversocket.h
index 7da75b96..b05aba91 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/private/aprserversocket.h
@@ -15,50 +15,33 @@
  * limitations under the License.
  */
 
-#ifndef _LOG4CXX_HELPERS_SERVER_SOCKET_H
-#define _LOG4CXX_HELPERS_SERVER_SOCKET_H
+#ifndef LOG4CXX_HELPERS_APRSERVERSOCKET_H
+#define LOG4CXX_HELPERS_APRSERVERSOCKET_H
 
-#include <log4cxx/helpers/socket.h>
-#include <mutex>
+#include <log4cxx/helpers/serversocket.h>
 
 namespace log4cxx
 {
 namespace helpers
 {
-class LOG4CXX_EXPORT ServerSocket
-{
-	public:
-		/**  Creates a server socket on a specified port.
-		*/
-		ServerSocket(int port);
-
-		virtual ~ServerSocket();
 
-		/** Listens for a connection to be made to this socket and
-		accepts it
-		*/
-		SocketPtr accept();
-
-		/** Closes this socket.
-		*/
-		void close();
+/**
+ * A ServerSocket that uses APR as the network implementation
+ */
+class LOG4CXX_EXPORT APRServerSocket : public helpers::ServerSocket
+{
+        public:
+            APRServerSocket(int port);
 
-		/** Retrive setting for SO_TIMEOUT.
-		*/
-		int getSoTimeout() const;
+	    void close();
 
-		/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
-		*/
-		void setSoTimeout(int timeout);
+	    SocketPtr accept();
 
 	private:
-		Pool pool;
-		std::mutex mutex;
-		apr_socket_t* socket;
-		int timeout;
-
+		struct APRServerSocketPriv;
 };
-}  // namespace helpers
-} // namespace log4cxx
 
-#endif //_LOG4CXX_HELPERS_SERVER_SOCKET_H
+}
+}
+
+#endif /* LOG4CXX_HELPERS_APRSERVERSOCKET_H */
diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/private/aprsocket.h
similarity index 55%
copy from src/main/include/log4cxx/helpers/serversocket.h
copy to src/main/include/log4cxx/private/aprsocket.h
index 7da75b96..5869a756 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/private/aprsocket.h
@@ -15,50 +15,37 @@
  * limitations under the License.
  */
 
-#ifndef _LOG4CXX_HELPERS_SERVER_SOCKET_H
-#define _LOG4CXX_HELPERS_SERVER_SOCKET_H
+#ifndef LOG4CXX_HELPERS_APRSOCKET_H
+#define LOG4CXX_HELPERS_APRSOCKET_H
 
 #include <log4cxx/helpers/socket.h>
-#include <mutex>
+
+struct apr_socket_t;
 
 namespace log4cxx
 {
 namespace helpers
 {
-class LOG4CXX_EXPORT ServerSocket
+
+class LOG4CXX_EXPORT APRSocket : public helpers::Socket
 {
 	public:
-		/**  Creates a server socket on a specified port.
+		/** Creates a stream socket and connects it to the specified port
+		number at the specified IP address.
 		*/
-		ServerSocket(int port);
-
-		virtual ~ServerSocket();
+		APRSocket(InetAddressPtr& address, int port);
+		APRSocket(apr_socket_t*, apr_pool_t* pool);
 
-		/** Listens for a connection to be made to this socket and
-		accepts it
-		*/
-		SocketPtr accept();
+		virtual size_t write(ByteBuffer&);
 
-		/** Closes this socket.
-		*/
-		void close();
-
-		/** Retrive setting for SO_TIMEOUT.
-		*/
-		int getSoTimeout() const;
-
-		/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
-		*/
-		void setSoTimeout(int timeout);
+		/** Closes this socket. */
+		virtual void close();
 
 	private:
-		Pool pool;
-		std::mutex mutex;
-		apr_socket_t* socket;
-		int timeout;
-
+		struct APRSocketPriv;
 };
-}  // namespace helpers
-} // namespace log4cxx
 
-#endif //_LOG4CXX_HELPERS_SERVER_SOCKET_H
+}
+}
+
+#endif /* LOG4CXX_HELPERS_APRSOCKET_H */
diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/private/serversocket_priv.h
similarity index 51%
copy from src/main/include/log4cxx/helpers/serversocket.h
copy to src/main/include/log4cxx/private/serversocket_priv.h
index 7da75b96..0d3b021d 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/private/serversocket_priv.h
@@ -15,50 +15,24 @@
  * limitations under the License.
  */
 
-#ifndef _LOG4CXX_HELPERS_SERVER_SOCKET_H
-#define _LOG4CXX_HELPERS_SERVER_SOCKET_H
+#ifndef LOG4CXX_HELPERS_SERVERSOCKET_PRIV_H
+#define LOG4CXX_HELPERS_SERVERSOCKET_PRIV_H
 
-#include <log4cxx/helpers/socket.h>
-#include <mutex>
+#include <log4cxx/helpers/serversocket.h>
 
 namespace log4cxx
 {
 namespace helpers
 {
-class LOG4CXX_EXPORT ServerSocket
-{
-	public:
-		/**  Creates a server socket on a specified port.
-		*/
-		ServerSocket(int port);
-
-		virtual ~ServerSocket();
-
-		/** Listens for a connection to be made to this socket and
-		accepts it
-		*/
-		SocketPtr accept();
-
-		/** Closes this socket.
-		*/
-		void close();
 
-		/** Retrive setting for SO_TIMEOUT.
-		*/
-		int getSoTimeout() const;
-
-		/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
-		*/
-		void setSoTimeout(int timeout);
-
-	private:
-		Pool pool;
-		std::mutex mutex;
-		apr_socket_t* socket;
-		int timeout;
+struct ServerSocket::ServerSocketPrivate{
+    ServerSocketPrivate() :
+        timeout(0){}
 
+    int timeout;
 };
-}  // namespace helpers
-} // namespace log4cxx
 
-#endif //_LOG4CXX_HELPERS_SERVER_SOCKET_H
+}
+}
+
+#endif /* LOG4CXX_HELPERS_SERVERSOCKET_PRIV_H */
diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/private/socket_priv.h
similarity index 53%
copy from src/main/include/log4cxx/helpers/serversocket.h
copy to src/main/include/log4cxx/private/socket_priv.h
index 7da75b96..fcc09bf7 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/private/socket_priv.h
@@ -15,50 +15,26 @@
  * limitations under the License.
  */
 
-#ifndef _LOG4CXX_HELPERS_SERVER_SOCKET_H
-#define _LOG4CXX_HELPERS_SERVER_SOCKET_H
+#ifndef LOG4CXX_HELPERS_SOCKET_PRIV_H
+#define LOG4CXX_HELPERS_SOCKET_PRIV_H
 
 #include <log4cxx/helpers/socket.h>
-#include <mutex>
 
 namespace log4cxx
 {
 namespace helpers
 {
-class LOG4CXX_EXPORT ServerSocket
-{
-	public:
-		/**  Creates a server socket on a specified port.
-		*/
-		ServerSocket(int port);
-
-		virtual ~ServerSocket();
-
-		/** Listens for a connection to be made to this socket and
-		accepts it
-		*/
-		SocketPtr accept();
-
-		/** Closes this socket.
-		*/
-		void close();
 
-		/** Retrive setting for SO_TIMEOUT.
-		*/
-		int getSoTimeout() const;
-
-		/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
-		*/
-		void setSoTimeout(int timeout);
-
-	private:
-		Pool pool;
-		std::mutex mutex;
-		apr_socket_t* socket;
-		int timeout;
+struct Socket::SocketPrivate{
+    /** The IP address of the remote end of this socket. */
+    InetAddressPtr address;
 
+    /** The port number on the remote host to which
+    this socket is connected. */
+    int port;
 };
-}  // namespace helpers
-} // namespace log4cxx
 
-#endif //_LOG4CXX_HELPERS_SERVER_SOCKET_H
+}
+}
+
+#endif /* LOG4CXX_HELPERS_SOCKET_PRIV_H */


[logging-log4cxx] 02/04: Remove uneeded forward declaration

Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d861ad56a132156394d39cd8e855387f2487d41b
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Aug 13 15:31:05 2022 -0400

    Remove uneeded forward declaration
---
 src/main/include/log4cxx/helpers/serversocket.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/main/include/log4cxx/helpers/serversocket.h b/src/main/include/log4cxx/helpers/serversocket.h
index b6cc51d7..c1847a78 100644
--- a/src/main/include/log4cxx/helpers/serversocket.h
+++ b/src/main/include/log4cxx/helpers/serversocket.h
@@ -21,8 +21,6 @@
 #include <log4cxx/helpers/socket.h>
 #include <mutex>
 
-struct apr_socket_t;
-
 namespace log4cxx
 {
 namespace helpers