]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/remote_logger.cc
2 #include "remote_logger.hh"
4 #ifdef PDNS_CONFIG_ARGS
6 #define WE_ARE_RECURSOR
11 bool RemoteLogger::reconnect()
18 d_socket
= SSocket(d_remote
.sin4
.sin_family
, SOCK_STREAM
, 0);
19 setNonBlocking(d_socket
);
20 SConnectWithTimeout(d_socket
, d_remote
, d_timeout
);
22 catch(const std::exception
& e
) {
23 #ifdef WE_ARE_RECURSOR
24 L
<<Logger::Warning
<<"Error connecting to remote logger "<<d_remote
.toStringWithPort()<<": "<<e
.what()<<std::endl
;
26 warnlog("Error connecting to remote logger %s: %s", d_remote
.toStringWithPort(), e
.what());
33 void RemoteLogger::worker()
42 std::unique_lock
<std::mutex
> lock(d_writeMutex
);
43 d_queueCond
.wait(lock
, [this]{return (!d_writeQueue
.empty()) || d_exiting
;});
47 data
= d_writeQueue
.front();
52 uint16_t len
= static_cast<uint16_t>(data
.length());
53 sendSizeAndMsgWithTimeout(d_socket
, len
, data
.c_str(), static_cast<int>(d_timeout
), nullptr, nullptr, 0, 0, 0);
55 catch(const std::runtime_error
& e
) {
56 #ifdef WE_ARE_RECURSOR
57 L
<<Logger::Info
<<"Error sending data to remote logger "<<d_remote
.toStringWithPort()<<": "<< e
.what()<<endl
;
59 vinfolog("Error sending data to remote logger (%s): %s", d_remote
.toStringWithPort(), e
.what());
61 while (!reconnect()) {
62 sleep(d_reconnectWaitTime
);
68 void RemoteLogger::queueData(const std::string
& data
)
71 std::unique_lock
<std::mutex
> lock(d_writeMutex
);
72 if (d_writeQueue
.size() >= d_maxQueuedEntries
) {
75 d_writeQueue
.push(data
);
77 d_queueCond
.notify_one();
80 RemoteLogger::RemoteLogger(const ComboAddress
& remote
, uint16_t timeout
, uint64_t maxQueuedEntries
, uint8_t reconnectWaitTime
, bool asyncConnect
): d_remote(remote
), d_maxQueuedEntries(maxQueuedEntries
), d_timeout(timeout
), d_reconnectWaitTime(reconnectWaitTime
), d_asyncConnect(asyncConnect
), d_thread(&RemoteLogger::worker
, this)
82 if (!d_asyncConnect
) {
87 RemoteLogger::~RemoteLogger()
94 d_queueCond
.notify_one();