]>
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()
19 d_socket
= SSocket(d_remote
.sin4
.sin_family
, SOCK_STREAM
, 0);
20 setNonBlocking(d_socket
);
21 SConnectWithTimeout(d_socket
, d_remote
, d_timeout
);
23 catch(const std::exception
& e
) {
24 #ifdef WE_ARE_RECURSOR
25 g_log
<<Logger::Warning
<<"Error connecting to remote logger "<<d_remote
.toStringWithPort()<<": "<<e
.what()<<std::endl
;
27 warnlog("Error connecting to remote logger %s: %s", d_remote
.toStringWithPort(), e
.what());
35 void RemoteLogger::busyReconnectLoop()
37 while (!reconnect()) {
38 sleep(d_reconnectWaitTime
);
42 void RemoteLogger::worker()
47 std::unique_lock
<std::mutex
> lock(d_writeMutex
);
48 d_queueCond
.wait(lock
, [this]{return (!d_writeQueue
.empty()) || d_exiting
;});
52 data
= d_writeQueue
.front();
61 uint16_t len
= static_cast<uint16_t>(data
.length());
62 sendSizeAndMsgWithTimeout(d_socket
, len
, data
.c_str(), static_cast<int>(d_timeout
), nullptr, nullptr, 0, 0, 0);
64 catch(const std::runtime_error
& e
) {
65 #ifdef WE_ARE_RECURSOR
66 g_log
<<Logger::Info
<<"Error sending data to remote logger "<<d_remote
.toStringWithPort()<<": "<< e
.what()<<endl
;
68 vinfolog("Error sending data to remote logger (%s): %s", d_remote
.toStringWithPort(), e
.what());
75 void RemoteLogger::queueData(const std::string
& data
)
78 std::unique_lock
<std::mutex
> lock(d_writeMutex
);
79 if (d_writeQueue
.size() >= d_maxQueuedEntries
) {
82 d_writeQueue
.push(data
);
84 d_queueCond
.notify_one();
87 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)
89 if (!d_asyncConnect
) {
94 RemoteLogger::~RemoteLogger()
102 d_queueCond
.notify_one();