]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/remote_logger.cc
2 #include "threadname.hh"
3 #include "remote_logger.hh"
7 #ifdef PDNS_CONFIG_ARGS
9 #define WE_ARE_RECURSOR
14 bool RemoteLogger::reconnect()
22 d_socket
= SSocket(d_remote
.sin4
.sin_family
, SOCK_STREAM
, 0);
23 setNonBlocking(d_socket
);
24 SConnectWithTimeout(d_socket
, d_remote
, d_timeout
);
26 catch(const std::exception
& e
) {
27 #ifdef WE_ARE_RECURSOR
28 g_log
<<Logger::Warning
<<"Error connecting to remote logger "<<d_remote
.toStringWithPort()<<": "<<e
.what()<<std::endl
;
30 warnlog("Error connecting to remote logger %s: %s", d_remote
.toStringWithPort(), e
.what());
38 void RemoteLogger::busyReconnectLoop()
40 while (!reconnect()) {
41 sleep(d_reconnectWaitTime
);
45 void RemoteLogger::worker()
47 #ifdef WE_ARE_RECURSOR
48 string threadName
= "pdns-r/remLog";
50 string threadName
= "dnsdist/remLog";
52 setThreadName(threadName
);
56 std::unique_lock
<std::mutex
> lock(d_writeMutex
);
57 d_queueCond
.wait(lock
, [this]{return (!d_writeQueue
.empty()) || d_exiting
;});
61 data
= d_writeQueue
.front();
70 uint16_t len
= static_cast<uint16_t>(data
.length());
71 sendSizeAndMsgWithTimeout(d_socket
, len
, data
.c_str(), static_cast<int>(d_timeout
), nullptr, nullptr, 0, 0, 0);
73 catch(const std::runtime_error
& e
) {
74 #ifdef WE_ARE_RECURSOR
75 g_log
<<Logger::Info
<<"Error sending data to remote logger "<<d_remote
.toStringWithPort()<<": "<< e
.what()<<endl
;
77 vinfolog("Error sending data to remote logger (%s): %s", d_remote
.toStringWithPort(), e
.what());
84 void RemoteLogger::queueData(const std::string
& data
)
87 std::lock_guard
<std::mutex
> lock(d_writeMutex
);
88 if (d_writeQueue
.size() >= d_maxQueuedEntries
) {
91 d_writeQueue
.push(data
);
93 d_queueCond
.notify_one();
96 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)
98 if (!d_asyncConnect
) {
103 RemoteLogger::~RemoteLogger()
111 d_queueCond
.notify_one();