mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
RemoteSyslogChannel/RemoteSyslogListener: make UDP buffer size configurable
This commit is contained in:
parent
5c0852ba04
commit
d1f72c6716
@ -124,6 +124,7 @@ public:
|
||||
/// by a colon) can also be specified.
|
||||
/// * host: (optional) Host name included in syslog messages. If not specified, the host's real domain name or
|
||||
/// IP address will be used.
|
||||
/// * buffer: UDP socket send buffer size in bytes. If not specified, the system default is used.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
@ -136,6 +137,7 @@ public:
|
||||
static const std::string PROP_FORMAT;
|
||||
static const std::string PROP_LOGHOST;
|
||||
static const std::string PROP_HOST;
|
||||
static const std::string PROP_BUFFER;
|
||||
static const std::string STRUCTURED_DATA;
|
||||
|
||||
protected:
|
||||
@ -148,6 +150,7 @@ private:
|
||||
std::string _host;
|
||||
int _facility;
|
||||
bool _bsdFormat;
|
||||
int _buffer;
|
||||
DatagramSocket _socket;
|
||||
SocketAddress _socketAddress;
|
||||
bool _open;
|
||||
|
@ -73,6 +73,8 @@ public:
|
||||
/// * threads: The number of parser threads processing
|
||||
/// received syslog messages. Defaults to 1. A maximum
|
||||
/// of 16 threads is supported.
|
||||
/// * buffer: The UDP socket receive buffer size in bytes. If not
|
||||
/// specified, the system default is used.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
@ -96,6 +98,7 @@ public:
|
||||
|
||||
static const std::string PROP_PORT;
|
||||
static const std::string PROP_THREADS;
|
||||
static const std::string PROP_BUFFER;
|
||||
|
||||
static const std::string LOG_PROP_APP;
|
||||
static const std::string LOG_PROP_HOST;
|
||||
@ -112,6 +115,7 @@ private:
|
||||
Poco::NotificationQueue _queue;
|
||||
Poco::UInt16 _port;
|
||||
int _threads;
|
||||
int _buffer;
|
||||
};
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/DNS.h"
|
||||
#include "Poco/LoggingFactory.h"
|
||||
@ -34,6 +35,7 @@ const std::string RemoteSyslogChannel::PROP_FACILITY("facility");
|
||||
const std::string RemoteSyslogChannel::PROP_FORMAT("format");
|
||||
const std::string RemoteSyslogChannel::PROP_LOGHOST("loghost");
|
||||
const std::string RemoteSyslogChannel::PROP_HOST("host");
|
||||
const std::string RemoteSyslogChannel::PROP_BUFFER("buffer");
|
||||
const std::string RemoteSyslogChannel::STRUCTURED_DATA("structured-data");
|
||||
|
||||
|
||||
@ -42,6 +44,7 @@ RemoteSyslogChannel::RemoteSyslogChannel():
|
||||
_name("-"),
|
||||
_facility(SYSLOG_USER),
|
||||
_bsdFormat(false),
|
||||
_buffer(0),
|
||||
_open(false)
|
||||
{
|
||||
}
|
||||
@ -52,6 +55,7 @@ RemoteSyslogChannel::RemoteSyslogChannel(const std::string& address, const std::
|
||||
_name(name),
|
||||
_facility(facility),
|
||||
_bsdFormat(bsdFormat),
|
||||
_buffer(0),
|
||||
_open(false)
|
||||
{
|
||||
if (_name.empty()) _name = "-";
|
||||
@ -95,6 +99,11 @@ void RemoteSyslogChannel::open()
|
||||
}
|
||||
}
|
||||
|
||||
if (_buffer)
|
||||
{
|
||||
_socket.setSendBufferSize(_buffer);
|
||||
}
|
||||
|
||||
_open = true;
|
||||
}
|
||||
|
||||
@ -233,6 +242,10 @@ void RemoteSyslogChannel::setProperty(const std::string& name, const std::string
|
||||
{
|
||||
_bsdFormat = (value == "bsd" || value == "rfc3164");
|
||||
}
|
||||
else if (name == PROP_BUFFER)
|
||||
{
|
||||
_buffer = Poco::NumberParser::parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Channel::setProperty(name, value);
|
||||
@ -314,6 +327,10 @@ std::string RemoteSyslogChannel::getProperty(const std::string& name) const
|
||||
{
|
||||
return _bsdFormat ? "rfc3164" : "rfc5424";
|
||||
}
|
||||
else if (name == PROP_BUFFER)
|
||||
{
|
||||
return Poco::NumberFormatter::format(_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Channel::getProperty(name);
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
BUFFER_SIZE = 65536
|
||||
};
|
||||
|
||||
RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port);
|
||||
RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, int buffer);
|
||||
~RemoteUDPListener();
|
||||
|
||||
void run();
|
||||
@ -100,11 +100,15 @@ private:
|
||||
};
|
||||
|
||||
|
||||
RemoteUDPListener::RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port):
|
||||
RemoteUDPListener::RemoteUDPListener(Poco::NotificationQueue& queue, Poco::UInt16 port, int buffer):
|
||||
_queue(queue),
|
||||
_socket(Poco::Net::SocketAddress(Poco::Net::IPAddress(), port)),
|
||||
_stopped(false)
|
||||
{
|
||||
if (buffer > 0)
|
||||
{
|
||||
_socket.setReceiveBufferSize(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -494,6 +498,7 @@ Poco::Message::Priority SyslogParser::convert(RemoteSyslogChannel::Severity seve
|
||||
|
||||
const std::string RemoteSyslogListener::PROP_PORT("port");
|
||||
const std::string RemoteSyslogListener::PROP_THREADS("threads");
|
||||
const std::string RemoteSyslogListener::PROP_BUFFER("buffer");
|
||||
|
||||
const std::string RemoteSyslogListener::LOG_PROP_APP("app");
|
||||
const std::string RemoteSyslogListener::LOG_PROP_HOST("host");
|
||||
@ -504,7 +509,8 @@ RemoteSyslogListener::RemoteSyslogListener():
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(RemoteSyslogChannel::SYSLOG_PORT),
|
||||
_threads(1)
|
||||
_threads(1),
|
||||
_buffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -513,7 +519,8 @@ RemoteSyslogListener::RemoteSyslogListener(Poco::UInt16 port):
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(port),
|
||||
_threads(1)
|
||||
_threads(1),
|
||||
_buffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -522,7 +529,8 @@ RemoteSyslogListener::RemoteSyslogListener(Poco::UInt16 port, int threads):
|
||||
_pListener(0),
|
||||
_pParser(0),
|
||||
_port(port),
|
||||
_threads(threads)
|
||||
_threads(threads),
|
||||
_buffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -564,6 +572,10 @@ void RemoteSyslogListener::setProperty(const std::string& name, const std::strin
|
||||
else
|
||||
throw Poco::InvalidArgumentException("Invalid number of threads", value);
|
||||
}
|
||||
else if (name == PROP_BUFFER)
|
||||
{
|
||||
_buffer = Poco::NumberParser::parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
SplitterChannel::setProperty(name, value);
|
||||
@ -577,6 +589,8 @@ std::string RemoteSyslogListener::getProperty(const std::string& name) const
|
||||
return Poco::NumberFormatter::format(_port);
|
||||
else if (name == PROP_THREADS)
|
||||
return Poco::NumberFormatter::format(_threads);
|
||||
else if (name == PROP_BUFFER)
|
||||
return Poco::NumberFormatter::format(_buffer);
|
||||
else
|
||||
return SplitterChannel::getProperty(name);
|
||||
}
|
||||
@ -588,7 +602,7 @@ void RemoteSyslogListener::open()
|
||||
_pParser = new SyslogParser(_queue, this);
|
||||
if (_port > 0)
|
||||
{
|
||||
_pListener = new RemoteUDPListener(_queue, _port);
|
||||
_pListener = new RemoteUDPListener(_queue, _port, _buffer);
|
||||
}
|
||||
for (int i = 0; i < _threads; i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user