Skip to content

Commit 167a0b1

Browse files
authored
Upgrade uvw to 3.X and fix/suppress some compiler warnings (#694)
1 parent d4f43a2 commit 167a0b1

21 files changed

+188
-162
lines changed

3rd/fstrm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_library(fstrm
1616
libmy/my_queue_mutex.c
1717
)
1818
add_library(fstrm::fstrm ALIAS fstrm)
19-
target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable)
19+
target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable -Wno-unused-but-set-variable)
2020

2121
target_include_directories(fstrm
2222
PUBLIC

cmd/pktvisord/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ int main(int argc, char *argv[])
593593
// if we are demonized, change to root directory now that (potentially) logs are open
594594
if (options.daemon) {
595595
#if __has_include(<unistd.h>)
596-
chdir("/");
596+
[[maybe_unused]] int result = chdir("/");
597597
#endif
598598
}
599599

conanfile.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[requires]
22
catch2/3.4.0
33
corrade/2020.06
4-
cpp-httplib/0.14.0
4+
cpp-httplib/0.14.1
55
docopt.cpp/0.6.3
66
fast-cpp-csv-parser/cci.20211104
77
json-schema-validator/2.2.0
88
libmaxminddb/1.7.1
99
nlohmann_json/3.11.2
10-
openssl/1.1.1k
10+
openssl/1.1.1w
1111
opentelemetry-proto/1.0.0
1212
pcapplusplus/22.11
1313
protobuf/3.21.12
1414
sigslot/1.2.2
1515
spdlog/1.12.0
16-
uvw/2.12.1
16+
uvw/3.2.0
1717
libpcap/1.10.4
1818
yaml-cpp/0.8.0
1919
robin-hood-hashing/3.11.5

src/IpPort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#ifdef __GNUC__
88
#pragma GCC diagnostic push
9+
#pragma GCC diagnostic ignored "-Wstringop-truncation"
910
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
1011
#endif
1112
#include <csv.h>

src/Metrics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66
#include <nlohmann/json.hpp>
7-
#include <opentelemetry/proto/metrics/v1/metrics.pb.h>
87
#include <sstream>
98
#include <timer.hpp>
109
#ifdef __GNUC__
@@ -17,6 +16,7 @@
1716
#include <cpc_sketch.hpp>
1817
#include <frequent_items_sketch.hpp>
1918
#include <kll_sketch.hpp>
19+
#include <opentelemetry/proto/metrics/v1/metrics.pb.h>
2020
#ifdef __GNUC__
2121
#pragma GCC diagnostic pop
2222
#endif

src/handlers/dns/v1/DnsStreamHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void DnsStreamHandler::start()
6464
_f_rcodes.push_back(NoError);
6565
} else if (config_exists("only_rcode")) {
6666
std::vector<std::string> rcodes;
67-
uint64_t want_code;
67+
uint64_t want_code{0};
6868
try {
6969
want_code = config_get<uint64_t>("only_rcode");
7070
} catch (const std::exception &e) {

src/handlers/dns/v2/DnsStreamHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void DnsStreamHandler::start()
6464
_f_rcodes.push_back(NoError);
6565
} else if (config_exists("only_rcode")) {
6666
std::vector<std::string> rcodes;
67-
uint64_t want_code;
67+
uint64_t want_code{0};
6868
try {
6969
want_code = config_get<uint64_t>("only_rcode");
7070
} catch (const std::exception &e) {

src/inputs/dnstap/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
44

55
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS pb/dnstap.proto)
66

7+
if(NOT WIN32)
8+
# Suppress the warning for the generated files
9+
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS}
10+
PROPERTIES COMPILE_FLAGS "-Wno-missing-declarations -Wno-unused-parameter"
11+
)
12+
endif()
13+
714
corrade_add_static_plugin(VisorInputDnstap ${CMAKE_CURRENT_BINARY_DIR}
815
Dnstap.conf
916
DnstapInputModulePlugin.cpp

src/inputs/dnstap/DnstapInputStream.cpp

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
#include "DnstapException.h"
77
#include "ThreadName.h"
88
#include <filesystem>
9+
#ifdef __GNUC__
10+
#pragma GCC diagnostic push
11+
#pragma GCC diagnostic ignored "-Wunused-parameter"
12+
#endif
913
#include <uvw/async.h>
1014
#include <uvw/loop.h>
1115
#include <uvw/pipe.h>
1216
#include <uvw/stream.h>
1317
#include <uvw/tcp.h>
1418
#include <uvw/timer.h>
19+
#ifdef __GNUC__
20+
#pragma GCC diagnostic pop
21+
#endif
1522

1623
namespace visor::input::dnstap {
1724

@@ -129,16 +136,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
129136
}
130137

131138
// main io loop, run in its own thread
132-
_io_loop = uvw::Loop::create();
139+
_io_loop = uvw::loop::create();
133140
if (!_io_loop) {
134141
throw DnstapException("unable to create io loop");
135142
}
136143
// AsyncHandle lets us stop the loop from its own thread
137-
_async_h = _io_loop->resource<uvw::AsyncHandle>();
144+
_async_h = _io_loop->resource<uvw::async_handle>();
138145
if (!_async_h) {
139146
throw DnstapException("unable to initialize AsyncHandle");
140147
}
141-
_async_h->once<uvw::AsyncEvent>([this](const auto &, auto &handle) {
148+
_async_h->on<uvw::async_event>([this](const auto &, auto &handle) {
142149
_timer->stop();
143150
_timer->close();
144151
_tcp_server_h->stop();
@@ -147,16 +154,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
147154
_io_loop->close();
148155
handle.close();
149156
});
150-
_async_h->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
157+
_async_h->on<uvw::error_event>([this](const auto &err, auto &handle) {
151158
_logger->error("[{}] AsyncEvent error: {}", _name, err.what());
152159
handle.close();
153160
});
154161

155-
_timer = _io_loop->resource<uvw::TimerHandle>();
162+
_timer = _io_loop->resource<uvw::timer_handle>();
156163
if (!_timer) {
157164
throw DnstapException("unable to initialize TimerHandle");
158165
}
159-
_timer->on<uvw::TimerEvent>([this](const auto &, auto &) {
166+
_timer->on<uvw::timer_event>([this](const auto &, auto &) {
160167
timespec stamp;
161168
// use now()
162169
std::timespec_get(&stamp, TIME_UTC);
@@ -165,25 +172,25 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
165172
static_cast<DnstapInputEventProxy *>(proxy.get())->heartbeat_cb(stamp);
166173
}
167174
});
168-
_timer->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
175+
_timer->on<uvw::error_event>([this](const auto &err, auto &handle) {
169176
_logger->error("[{}] TimerEvent error: {}", _name, err.what());
170177
handle.close();
171178
});
172179

173180
// setup server socket
174-
_tcp_server_h = _io_loop->resource<uvw::TCPHandle>();
181+
_tcp_server_h = _io_loop->resource<uvw::tcp_handle>();
175182
if (!_tcp_server_h) {
176-
throw DnstapException("unable to initialize server PipeHandle");
183+
throw DnstapException("unable to initialize server pipe_handle");
177184
}
178185

179-
_tcp_server_h->on<uvw::ErrorEvent>([this](const auto &err, auto &) {
186+
_tcp_server_h->on<uvw::error_event>([this](const auto &err, auto &) {
180187
_logger->error("[{}] socket error: {}", _name, err.what());
181188
throw DnstapException(err.what());
182189
});
183190

184-
// ListenEvent happens on client connection
185-
_tcp_server_h->on<uvw::ListenEvent>([this](const uvw::ListenEvent &, uvw::TCPHandle &) {
186-
auto client = _io_loop->resource<uvw::TCPHandle>();
191+
// listen_event happens on client connection
192+
_tcp_server_h->on<uvw::listen_event>([this](const uvw::listen_event &, uvw::tcp_handle &) {
193+
auto client = _io_loop->resource<uvw::tcp_handle>();
187194
if (!client) {
188195
throw DnstapException("unable to initialize connected client TCPHandle");
189196
}
@@ -209,14 +216,14 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
209216
}
210217
};
211218

212-
client->on<uvw::ErrorEvent>([this](const uvw::ErrorEvent &err, uvw::TCPHandle &c_sock) {
219+
client->on<uvw::error_event>([this](const uvw::error_event &err, uvw::tcp_handle &c_sock) {
213220
_logger->error("[{}]: dnstap client socket error: {}", _name, err.what());
214221
c_sock.stop();
215222
c_sock.close();
216223
});
217224

218225
// client sent data
219-
client->on<uvw::DataEvent>([this](const uvw::DataEvent &data, uvw::TCPHandle &c_sock) {
226+
client->on<uvw::data_event>([this](const uvw::data_event &data, uvw::tcp_handle &c_sock) {
220227
assert(_tcp_sessions[c_sock.fd()]);
221228
try {
222229
_tcp_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast<uint8_t *>(data.data.get()), data.length);
@@ -227,20 +234,20 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
227234
}
228235
});
229236
// client was closed
230-
client->on<uvw::CloseEvent>([this](const uvw::CloseEvent &, uvw::TCPHandle &c_sock) {
237+
client->on<uvw::close_event>([this](const uvw::close_event &, uvw::tcp_handle &c_sock) {
231238
_logger->info("[{}]: dnstap client disconnected", _name);
232239
_tcp_sessions.erase(c_sock.fd());
233240
});
234241
// client read EOF
235-
client->on<uvw::EndEvent>([this](const uvw::EndEvent &, uvw::TCPHandle &c_sock) {
242+
client->on<uvw::end_event>([this](const uvw::end_event &, uvw::tcp_handle &c_sock) {
236243
_logger->info("[{}]: dnstap client EOF {}", _name, c_sock.peer().ip);
237244
c_sock.stop();
238245
c_sock.close();
239246
});
240247

241248
_tcp_server_h->accept(*client);
242249
_logger->info("[{}]: dnstap client connected {}", _name, client->peer().ip);
243-
_tcp_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::TCPHandle>>(client, CONTENT_TYPE, on_data_frame);
250+
_tcp_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::tcp_handle>>(client, CONTENT_TYPE, on_data_frame);
244251
client->read();
245252
});
246253

@@ -250,7 +257,7 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
250257

251258
// spawn the loop
252259
_io_thread = std::make_unique<std::thread>([this] {
253-
_timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000});
260+
_timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000});
254261
thread::change_self_name(schema_key(), name());
255262
_io_loop->run();
256263
});
@@ -260,16 +267,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
260267
assert(config_exists("socket"));
261268

262269
// main io loop, run in its own thread
263-
_io_loop = uvw::Loop::create();
270+
_io_loop = uvw::loop::create();
264271
if (!_io_loop) {
265272
throw DnstapException("unable to create io loop");
266273
}
267274
// AsyncHandle lets us stop the loop from its own thread
268-
_async_h = _io_loop->resource<uvw::AsyncHandle>();
275+
_async_h = _io_loop->resource<uvw::async_handle>();
269276
if (!_async_h) {
270277
throw DnstapException("unable to initialize AsyncHandle");
271278
}
272-
_async_h->once<uvw::AsyncEvent>([this](const auto &, auto &handle) {
279+
_async_h->on<uvw::async_event>([this](const auto &, auto &handle) {
273280
_timer->stop();
274281
_timer->close();
275282
_unix_server_h->stop();
@@ -278,16 +285,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
278285
_io_loop->close();
279286
handle.close();
280287
});
281-
_async_h->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
288+
_async_h->on<uvw::error_event>([this](const auto &err, auto &handle) {
282289
_logger->error("[{}] AsyncEvent error: {}", _name, err.what());
283290
handle.close();
284291
});
285292

286-
_timer = _io_loop->resource<uvw::TimerHandle>();
293+
_timer = _io_loop->resource<uvw::timer_handle>();
287294
if (!_timer) {
288295
throw DnstapException("unable to initialize TimerHandle");
289296
}
290-
_timer->on<uvw::TimerEvent>([this](const auto &, auto &) {
297+
_timer->on<uvw::timer_event>([this](const auto &, auto &) {
291298
timespec stamp;
292299
// use now()
293300
std::timespec_get(&stamp, TIME_UTC);
@@ -296,27 +303,27 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
296303
static_cast<DnstapInputEventProxy *>(proxy.get())->heartbeat_cb(stamp);
297304
}
298305
});
299-
_timer->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
306+
_timer->on<uvw::error_event>([this](const auto &err, auto &handle) {
300307
_logger->error("[{}] TimerEvent error: {}", _name, err.what());
301308
handle.close();
302309
});
303310

304311
// setup server socket
305-
_unix_server_h = _io_loop->resource<uvw::PipeHandle>();
312+
_unix_server_h = _io_loop->resource<uvw::pipe_handle>();
306313
if (!_unix_server_h) {
307-
throw DnstapException("unable to initialize server PipeHandle");
314+
throw DnstapException("unable to initialize server pipe_handle");
308315
}
309316

310-
_unix_server_h->on<uvw::ErrorEvent>([this](const auto &err, auto &) {
317+
_unix_server_h->on<uvw::error_event>([this](const auto &err, auto &) {
311318
_logger->error("[{}] socket error: {}", _name, err.what());
312319
throw DnstapException(err.what());
313320
});
314321

315-
// ListenEvent happens on client connection
316-
_unix_server_h->on<uvw::ListenEvent>([this](const uvw::ListenEvent &, uvw::PipeHandle &) {
317-
auto client = _io_loop->resource<uvw::PipeHandle>();
322+
// listen_event happens on client connection
323+
_unix_server_h->on<uvw::listen_event>([this](const uvw::listen_event &, uvw::pipe_handle &) {
324+
auto client = _io_loop->resource<uvw::pipe_handle>();
318325
if (!client) {
319-
throw DnstapException("unable to initialize connected client PipeHandle");
326+
throw DnstapException("unable to initialize connected client pipe_handle");
320327
}
321328

322329
auto on_data_frame = [this](const void *data, std::size_t len_data) {
@@ -339,14 +346,14 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
339346
}
340347
};
341348

342-
client->on<uvw::ErrorEvent>([this](const uvw::ErrorEvent &err, uvw::PipeHandle &c_sock) {
349+
client->on<uvw::error_event>([this](const uvw::error_event &err, uvw::pipe_handle &c_sock) {
343350
_logger->error("[{}]: dnstap client socket error: {}", _name, err.what());
344351
c_sock.stop();
345352
c_sock.close();
346353
});
347354

348355
// client sent data
349-
client->on<uvw::DataEvent>([this](const uvw::DataEvent &data, uvw::PipeHandle &c_sock) {
356+
client->on<uvw::data_event>([this](const uvw::data_event &data, uvw::pipe_handle &c_sock) {
350357
assert(_unix_sessions[c_sock.fd()]);
351358
try {
352359
_unix_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast<uint8_t *>(data.data.get()), data.length);
@@ -357,20 +364,20 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
357364
}
358365
});
359366
// client was closed
360-
client->on<uvw::CloseEvent>([this](const uvw::CloseEvent &, uvw::PipeHandle &c_sock) {
367+
client->on<uvw::close_event>([this](const uvw::close_event &, uvw::pipe_handle &c_sock) {
361368
_logger->info("[{}]: dnstap client disconnected", _name);
362369
_unix_sessions.erase(c_sock.fd());
363370
});
364371
// client read EOF
365-
client->on<uvw::EndEvent>([this](const uvw::EndEvent &, uvw::PipeHandle &c_sock) {
372+
client->on<uvw::end_event>([this](const uvw::end_event &, uvw::pipe_handle &c_sock) {
366373
_logger->info("[{}]: dnstap client EOF {}", _name, c_sock.sock());
367374
c_sock.stop();
368375
c_sock.close();
369376
});
370377

371378
_unix_server_h->accept(*client);
372379
_logger->info("[{}]: dnstap client connected {}", _name, client->sock());
373-
_unix_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::PipeHandle>>(client, CONTENT_TYPE, on_data_frame);
380+
_unix_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::pipe_handle>>(client, CONTENT_TYPE, on_data_frame);
374381
client->read();
375382
});
376383

@@ -383,7 +390,7 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
383390

384391
// spawn the loop
385392
_io_thread = std::make_unique<std::thread>([this] {
386-
_timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000});
393+
_timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000});
387394
thread::change_self_name(schema_key(), name());
388395
_io_loop->run();
389396
});

0 commit comments

Comments
 (0)