diff --git a/Net/include/Poco/Net/RemoteSyslogChannel.h b/Net/include/Poco/Net/RemoteSyslogChannel.h index 66b60a7c0..64a0db83c 100644 --- a/Net/include/Poco/Net/RemoteSyslogChannel.h +++ b/Net/include/Poco/Net/RemoteSyslogChannel.h @@ -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; diff --git a/Net/include/Poco/Net/RemoteSyslogListener.h b/Net/include/Poco/Net/RemoteSyslogListener.h index 93895244c..cedf7330a 100644 --- a/Net/include/Poco/Net/RemoteSyslogListener.h +++ b/Net/include/Poco/Net/RemoteSyslogListener.h @@ -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; }; diff --git a/Net/src/RemoteSyslogChannel.cpp b/Net/src/RemoteSyslogChannel.cpp index f66248ab0..3efc30d1c 100644 --- a/Net/src/RemoteSyslogChannel.cpp +++ b/Net/src/RemoteSyslogChannel.cpp @@ -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); diff --git a/Net/src/RemoteSyslogListener.cpp b/Net/src/RemoteSyslogListener.cpp index 5a319ea7e..a06a54b5a 100644 --- a/Net/src/RemoteSyslogListener.cpp +++ b/Net/src/RemoteSyslogListener.cpp @@ -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++) {