mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-27 10:25:59 +02:00
#3242: RemoteSyslogListener: add reusePort option
This commit is contained in:
parent
cae2f2dea4
commit
e4bdfdff0c
@ -55,6 +55,13 @@ public:
|
||||
/// Depending on the address family, the socket
|
||||
/// will be either an IPv4 or an IPv6 socket.
|
||||
|
||||
DatagramSocket(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||
/// Creates a datagram socket and binds it
|
||||
/// to the given address.
|
||||
///
|
||||
/// Depending on the address family, the socket
|
||||
/// will be either an IPv4 or an IPv6 socket.
|
||||
|
||||
DatagramSocket(const Socket& socket);
|
||||
/// Creates the DatagramSocket with the SocketImpl
|
||||
/// from another socket. The SocketImpl must be
|
||||
|
@ -63,6 +63,13 @@ public:
|
||||
/// Creates the RemoteSyslogListener, listening on the given port number
|
||||
/// and using the number of threads for message processing.
|
||||
|
||||
RemoteSyslogListener(Poco::UInt16 port, bool reusePort, int threads);
|
||||
/// Creates the RemoteSyslogListener, listening on the given port number
|
||||
/// and using the number of threads for message processing.
|
||||
///
|
||||
/// If reusePort is true, the underlying UDP socket will bind
|
||||
/// with the reusePort flag set.
|
||||
|
||||
void setProperty(const std::string& name, const std::string& value);
|
||||
/// Sets the property with the given value.
|
||||
///
|
||||
@ -70,6 +77,8 @@ public:
|
||||
/// * port: The UDP port number where to listen for UDP packets
|
||||
/// containing syslog messages. If 0 is specified, does not
|
||||
/// listen for UDP messages.
|
||||
/// * reusePort: If set to true, allows multiple instances
|
||||
/// binding to the same port number.
|
||||
/// * threads: The number of parser threads processing
|
||||
/// received syslog messages. Defaults to 1. A maximum
|
||||
/// of 16 threads is supported.
|
||||
@ -97,6 +106,7 @@ public:
|
||||
/// Registers the channel with the global LoggingFactory.
|
||||
|
||||
static const std::string PROP_PORT;
|
||||
static const std::string PROP_REUSE_PORT;
|
||||
static const std::string PROP_THREADS;
|
||||
static const std::string PROP_BUFFER;
|
||||
|
||||
@ -114,6 +124,7 @@ private:
|
||||
Poco::ThreadPool _threadPool;
|
||||
Poco::NotificationQueue _queue;
|
||||
Poco::UInt16 _port;
|
||||
bool _reusePort;
|
||||
int _threads;
|
||||
int _buffer;
|
||||
};
|
||||
|
@ -40,6 +40,12 @@ DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress):
|
||||
}
|
||||
|
||||
|
||||
DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress, bool reusePort): Socket(new DatagramSocketImpl(address.family()))
|
||||
{
|
||||
bind(address, reuseAddress, reusePort);
|
||||
}
|
||||
|
||||
|
||||
DatagramSocket::DatagramSocket(const Socket& socket): Socket(socket)
|
||||
{
|
||||
if (!dynamic_cast<DatagramSocketImpl*>(impl()))
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
BUFFER_SIZE = 65536
|
||||
};
|
||||
|
||||
RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, int buffer);
|
||||
RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, bool reusePort, int buffer);
|
||||
~RemoteUDPListener();
|
||||
|
||||
void run();
|
||||
@ -100,9 +100,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
RemoteUDPListener::RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, int buffer):
|
||||
RemoteUDPListener::RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, bool reusePort, int buffer):
|
||||
_queue(queue),
|
||||
_socket(Poco::Net::SocketAddress(Poco::Net::IPAddress(), port)),
|
||||
_socket(Poco::Net::SocketAddress(Poco::Net::IPAddress(), port), false, reusePort),
|
||||
_stopped(false)
|
||||
{
|
||||
if (buffer > 0)
|
||||
@ -497,6 +497,7 @@ Poco::Message::Priority SyslogParser::convert(RemoteSyslogChannel::Severity seve
|
||||
|
||||
|
||||
const std::string RemoteSyslogListener::PROP_PORT("port");
|
||||
const std::string RemoteSyslogListener::PROP_REUSE_PORT("reusePort");
|
||||
const std::string RemoteSyslogListener::PROP_THREADS("threads");
|
||||
const std::string RemoteSyslogListener::PROP_BUFFER("buffer");
|
||||
|
||||
@ -509,6 +510,7 @@ RemoteSyslogListener::RemoteSyslogListener():
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(RemoteSyslogChannel::SYSLOG_PORT),
|
||||
_reusePort(false),
|
||||
_threads(1),
|
||||
_buffer(0)
|
||||
{
|
||||
@ -519,6 +521,7 @@ RemoteSyslogListener::RemoteSyslogListener(Poco::UInt16 port):
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(port),
|
||||
_reusePort(false),
|
||||
_threads(1),
|
||||
_buffer(0)
|
||||
{
|
||||
@ -529,6 +532,18 @@ RemoteSyslogListener::RemoteSyslogListener(Poco::UInt16 port, int threads):
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(port),
|
||||
_reusePort(false),
|
||||
_threads(threads),
|
||||
_buffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RemoteSyslogListener::RemoteSyslogListener(Poco::UInt16 port, bool reusePort, int threads):
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(port),
|
||||
_reusePort(reusePort),
|
||||
_threads(threads),
|
||||
_buffer(0)
|
||||
{
|
||||
@ -564,6 +579,10 @@ void RemoteSyslogListener::setProperty(const std::string& name, const std::strin
|
||||
else
|
||||
throw Poco::InvalidArgumentException("Not a valid port number", value);
|
||||
}
|
||||
else if (name == PROP_REUSE_PORT)
|
||||
{
|
||||
_reusePort = Poco::NumberParser::parseBool(value);
|
||||
}
|
||||
else if (name == PROP_THREADS)
|
||||
{
|
||||
int val = Poco::NumberParser::parse(value);
|
||||
@ -587,6 +606,8 @@ std::string RemoteSyslogListener::getProperty(const std::string& name) const
|
||||
{
|
||||
if (name == PROP_PORT)
|
||||
return Poco::NumberFormatter::format(_port);
|
||||
else if (name == PROP_REUSE_PORT)
|
||||
return Poco::NumberFormatter::format(_reusePort);
|
||||
else if (name == PROP_THREADS)
|
||||
return Poco::NumberFormatter::format(_threads);
|
||||
else if (name == PROP_BUFFER)
|
||||
@ -602,7 +623,7 @@ void RemoteSyslogListener::open()
|
||||
_pParser = new SyslogParser(_queue, this);
|
||||
if (_port > 0)
|
||||
{
|
||||
_pListener = new RemoteUDPListener(_queue, _port, _buffer);
|
||||
_pListener = new RemoteUDPListener(_queue, _port, _reusePort, _buffer);
|
||||
}
|
||||
for (int i = 0; i < _threads; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user