1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
diff --git a/Makefile b/Makefile
index 784a1f1..3e05272 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ CFLAGS += -Wall -Werror -O2 -g -Ilibs
CXX ?= g++
CXXFLAGS += -std=c++11 -Wall -Wno-psabi -Werror -O2 -g -Ilibs
-LIBS=-lboost_system -lboost_program_options -lboost_regex -lboost_filesystem -lpthread
+LIBS= -lboost_program_options -lboost_regex -lboost_filesystem -lpthread
LIBS_SDR=-lSoapySDR
all: dump978-fa skyaware978
diff --git a/dump978_main.cc b/dump978_main.cc
index a8faa6d..c0e1015 100644
--- a/dump978_main.cc
+++ b/dump978_main.cc
@@ -76,7 +76,7 @@ namespace flightaware::uat {
#define EXIT_NO_RESTART (64)
static int realmain(int argc, char **argv) {
- boost::asio::io_service io_service;
+ boost::asio::io_context io_service;
// clang-format off
po::options_description desc("Allowed options");
@@ -157,13 +157,13 @@ static int realmain(int argc, char **argv) {
bool ok = true;
for (auto l : opts[option].as<std::vector<listen_option>>()) {
- tcp::resolver::query query(l.host, l.port, tcp::resolver::query::passive);
+ // New resolver API (Boost 1.87+)
boost::system::error_code ec;
bool success = false;
- tcp::resolver::iterator end;
- for (auto i = resolver.resolve(query, ec); i != end; ++i) {
- const auto &endpoint = i->endpoint();
+ auto results = resolver.resolve(l.host, l.port, tcp::resolver::passive, ec);
+ for (const auto& entry : results) {
+ const auto &endpoint = entry.endpoint();
try {
auto listener = SocketListener::Create(io_service, endpoint, dispatch, factory);
diff --git a/faup978_main.cc b/faup978_main.cc
index 9636e0b..7b8017f 100644
--- a/faup978_main.cc
+++ b/faup978_main.cc
@@ -42,7 +42,7 @@ void validate(boost::any &v, const std::vector<std::string> &values, connect_opt
#define EXIT_NO_RESTART (64)
static int realmain(int argc, char **argv) {
- boost::asio::io_service io_service;
+ boost::asio::io_context io_service;
// clang-format off
po::options_description desc("Allowed options");
diff --git a/faup978_reporter.cc b/faup978_reporter.cc
index 75dfed0..494cfd5 100644
--- a/faup978_reporter.cc
+++ b/faup978_reporter.cc
@@ -59,7 +59,7 @@ void Reporter::PurgeOld() {
}
auto self(shared_from_this());
- purge_timer_.expires_from_now(timeout_ / 4);
+ purge_timer_.expires_after(timeout_ / 4);
purge_timer_.async_wait(strand_.wrap([this, self](const boost::system::error_code &ec) {
if (!ec) {
PurgeOld();
@@ -88,7 +88,7 @@ void Reporter::PeriodicReport() {
}
auto self(shared_from_this());
- report_timer_.expires_from_now(interval_);
+ report_timer_.expires_after(interval_);
report_timer_.async_wait(strand_.wrap([this, self](const boost::system::error_code &ec) {
if (!ec) {
PeriodicReport();
diff --git a/faup978_reporter.h b/faup978_reporter.h
index 450b981..014fdea 100644
--- a/faup978_reporter.h
+++ b/faup978_reporter.h
@@ -10,7 +10,7 @@
#include <chrono>
#include <memory>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/strand.hpp>
@@ -31,7 +31,7 @@ namespace flightaware::faup978 {
static constexpr const char *TSV_VERSION_8U = "8U";
static constexpr const char *TSV_VERSION_8U_FIX = "8UF";
- static Pointer Create(boost::asio::io_service &service, std::chrono::milliseconds interval = std::chrono::milliseconds(500), std::chrono::milliseconds timeout = std::chrono::seconds(300)) { return Pointer(new Reporter(service, interval, timeout)); }
+ static Pointer Create(boost::asio::io_context &service, std::chrono::milliseconds interval = std::chrono::milliseconds(500), std::chrono::milliseconds timeout = std::chrono::seconds(300)) { return Pointer(new Reporter(service, interval, timeout)); }
void Start();
void Stop();
@@ -39,7 +39,7 @@ namespace flightaware::faup978 {
void HandleMessages(flightaware::uat::SharedMessageVector messages);
private:
- Reporter(boost::asio::io_service &service, std::chrono::milliseconds interval, std::chrono::milliseconds timeout) : service_(service), strand_(service), report_timer_(service), purge_timer_(service), interval_(interval), timeout_(timeout) { tracker_ = flightaware::uat::Tracker::Create(service, timeout); }
+ Reporter(boost::asio::io_context &service, std::chrono::milliseconds interval, std::chrono::milliseconds timeout) : service_(service), strand_(service), report_timer_(service), purge_timer_(service), interval_(interval), timeout_(timeout) { tracker_ = flightaware::uat::Tracker::Create(service, timeout); }
void PeriodicReport();
void PurgeOld();
@@ -47,8 +47,8 @@ namespace flightaware::faup978 {
const char *TSVVersion() const { return fecfix_ ? TSV_VERSION_8U_FIX : TSV_VERSION_8U; }
- boost::asio::io_service &service_;
- boost::asio::io_service::strand strand_;
+ boost::asio::io_context &service_;
+ boost::asio::io_context::strand strand_;
boost::asio::steady_timer report_timer_;
boost::asio::steady_timer purge_timer_;
std::chrono::milliseconds interval_;
diff --git a/sample_source.cc b/sample_source.cc
index 8f187e8..3ac9e0d 100644
--- a/sample_source.cc
+++ b/sample_source.cc
@@ -3,6 +3,7 @@
// Licensed under the 2-clause BSD license; see the LICENSE file
#include "sample_source.h"
+#include <boost/asio/post.hpp>
#include <chrono>
#include <iostream>
@@ -22,7 +23,7 @@ void FileSampleSource::Start() {
timestamp_ = 1; // always use synthetic timestamps for file sources
auto self = std::static_pointer_cast<FileSampleSource>(shared_from_this());
- service_.post(std::bind(&FileSampleSource::ReadBlock, self, boost::system::error_code()));
+ boost::asio::post(service_, std::bind(&FileSampleSource::ReadBlock, self, boost::system::error_code()));
}
void FileSampleSource::Stop() {
@@ -77,7 +78,7 @@ void FileSampleSource::ReadBlock(const boost::system::error_code &ec) {
timer_.expires_at(next_block_);
timer_.async_wait(std::bind(&FileSampleSource::ReadBlock, self, std::placeholders::_1));
} else {
- service_.post(std::bind(&FileSampleSource::ReadBlock, self, boost::system::error_code()));
+ boost::asio::post(service_, std::bind(&FileSampleSource::ReadBlock, self, boost::system::error_code()));
}
}
diff --git a/sample_source.h b/sample_source.h
index 4c52fb2..61ea084 100644
--- a/sample_source.h
+++ b/sample_source.h
@@ -12,7 +12,7 @@
#include <functional>
#include <memory>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/filesystem.hpp>
@@ -60,7 +60,7 @@ namespace flightaware::uat {
class FileSampleSource : public SampleSource {
public:
- static SampleSource::Pointer Create(boost::asio::io_service &service, const boost::filesystem::path &path, const boost::program_options::variables_map &options = boost::program_options::variables_map(), std::size_t samples_per_second = 2083333, std::size_t samples_per_block = 524288) { return Pointer(new FileSampleSource(service, path, options, samples_per_second, samples_per_block)); }
+ static SampleSource::Pointer Create(boost::asio::io_context &service, const boost::filesystem::path &path, const boost::program_options::variables_map &options = boost::program_options::variables_map(), std::size_t samples_per_second = 2083333, std::size_t samples_per_block = 524288) { return Pointer(new FileSampleSource(service, path, options, samples_per_second, samples_per_block)); }
void Init() override {}
void Start() override;
@@ -68,7 +68,7 @@ namespace flightaware::uat {
SampleFormat Format() override { return format_; }
private:
- FileSampleSource(boost::asio::io_service &service, const boost::filesystem::path &path, const boost::program_options::variables_map &options, std::size_t samples_per_second, std::size_t samples_per_block) : service_(service), path_(path), timer_(service) {
+ FileSampleSource(boost::asio::io_context &service, const boost::filesystem::path &path, const boost::program_options::variables_map &options, std::size_t samples_per_second, std::size_t samples_per_block) : service_(service), path_(path), timer_(service) {
if (!options.count("format")) {
throw std::runtime_error("--format must be specified when using a file input");
}
@@ -83,7 +83,7 @@ namespace flightaware::uat {
void ReadBlock(const boost::system::error_code &ec);
- boost::asio::io_service &service_;
+ boost::asio::io_context &service_;
boost::filesystem::path path_;
SampleFormat format_;
unsigned alignment_;
@@ -99,7 +99,7 @@ namespace flightaware::uat {
class StdinSampleSource : public SampleSource {
public:
- static SampleSource::Pointer Create(boost::asio::io_service &service, const boost::program_options::variables_map &options, std::size_t samples_per_second = 2083333, std::size_t samples_per_block = 524288) { return Pointer(new StdinSampleSource(service, options, samples_per_second, samples_per_block)); }
+ static SampleSource::Pointer Create(boost::asio::io_context &service, const boost::program_options::variables_map &options, std::size_t samples_per_second = 2083333, std::size_t samples_per_block = 524288) { return Pointer(new StdinSampleSource(service, options, samples_per_second, samples_per_block)); }
void Init() override {}
void Start() override;
@@ -107,7 +107,7 @@ namespace flightaware::uat {
SampleFormat Format() override { return format_; }
private:
- StdinSampleSource(boost::asio::io_service &service, const boost::program_options::variables_map &options, std::size_t samples_per_second, std::size_t samples_per_block) : service_(service), samples_per_second_(samples_per_second), stream_(service), used_(0) {
+ StdinSampleSource(boost::asio::io_context &service, const boost::program_options::variables_map &options, std::size_t samples_per_second, std::size_t samples_per_block) : service_(service), samples_per_second_(samples_per_second), stream_(service), used_(0) {
if (!options.count("format")) {
throw std::runtime_error("--format must be specified when using a file input");
}
@@ -119,7 +119,7 @@ namespace flightaware::uat {
void ScheduleRead();
- boost::asio::io_service &service_;
+ boost::asio::io_context &service_;
SampleFormat format_;
unsigned alignment_;
std::size_t samples_per_second_;
diff --git a/skyaware978_main.cc b/skyaware978_main.cc
index 0f05b43..3eb3cda 100644
--- a/skyaware978_main.cc
+++ b/skyaware978_main.cc
@@ -42,7 +42,7 @@ void validate(boost::any &v, const std::vector<std::string> &values, connect_opt
#define EXIT_NO_RESTART (64)
static int realmain(int argc, char **argv) {
- boost::asio::io_service io_service;
+ boost::asio::io_context io_service;
// clang-format off
po::options_description desc("Allowed options");
diff --git a/skyaware_writer.cc b/skyaware_writer.cc
index 620eee4..64dc5e4 100644
--- a/skyaware_writer.cc
+++ b/skyaware_writer.cc
@@ -218,7 +218,7 @@ void SkyAwareWriter::PeriodicWrite() {
}
auto self(shared_from_this());
- timer_.expires_from_now(interval_);
+ timer_.expires_after(interval_);
timer_.async_wait(strand_.wrap([this, self](const boost::system::error_code &ec) {
if (!ec) {
PeriodicWrite();
diff --git a/skyaware_writer.h b/skyaware_writer.h
index aa67160..044a5fe 100644
--- a/skyaware_writer.h
+++ b/skyaware_writer.h
@@ -10,7 +10,7 @@
#include <chrono>
#include <memory>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/strand.hpp>
#include <boost/filesystem.hpp>
@@ -23,18 +23,18 @@ namespace flightaware::skyaware {
public:
typedef std::shared_ptr<SkyAwareWriter> Pointer;
- static Pointer Create(boost::asio::io_service &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) { return Pointer(new SkyAwareWriter(service, tracker, dir, interval, history_count, history_interval, location)); }
+ static Pointer Create(boost::asio::io_context &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) { return Pointer(new SkyAwareWriter(service, tracker, dir, interval, history_count, history_interval, location)); }
void Start();
void Stop();
private:
- SkyAwareWriter(boost::asio::io_service &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) : service_(service), strand_(service), timer_(service), tracker_(tracker), dir_(dir), interval_(interval), history_count_(history_count), history_interval_(history_interval), location_(location) {}
+ SkyAwareWriter(boost::asio::io_context &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) : service_(service), strand_(service), timer_(service), tracker_(tracker), dir_(dir), interval_(interval), history_count_(history_count), history_interval_(history_interval), location_(location) {}
void PeriodicWrite();
- boost::asio::io_service &service_;
- boost::asio::io_service::strand strand_;
+ boost::asio::io_context &service_;
+ boost::asio::io_context::strand strand_;
boost::asio::steady_timer timer_;
flightaware::uat::Tracker::Pointer tracker_;
boost::filesystem::path dir_;
diff --git a/soapy_source.cc b/soapy_source.cc
index b427b8e..5f0cb14 100644
--- a/soapy_source.cc
+++ b/soapy_source.cc
@@ -141,7 +141,7 @@ class SoapySDRCategory : public boost::system::error_category {
static SoapySDRCategory soapysdr_category;
-SoapySampleSource::SoapySampleSource(boost::asio::io_service &service, const std::string &device_name, const boost::program_options::variables_map &options) : timer_(service), device_name_(device_name), options_(options) {
+SoapySampleSource::SoapySampleSource(boost::asio::io_context &service, const std::string &device_name, const boost::program_options::variables_map &options) : timer_(service), device_name_(device_name), options_(options) {
if (!log_handler_registered_.exchange(true)) {
SoapySDR::registerLogHandler(SoapyLogger);
SoapySDR::setLogLevel(SOAPY_SDR_NOTICE);
@@ -279,7 +279,7 @@ void SoapySampleSource::Keepalive() {
if (rx_thread_ && rx_thread_->joinable()) {
// Keep the io_service alive while the rx_thread is active
auto self(shared_from_this());
- timer_.expires_from_now(std::chrono::milliseconds(1000));
+ timer_.expires_after(std::chrono::milliseconds(1000));
timer_.async_wait([self, this](const boost::system::error_code &ec) {
if (!ec) {
Keepalive();
diff --git a/soapy_source.h b/soapy_source.h
index f0f64ba..aac3f56 100644
--- a/soapy_source.h
+++ b/soapy_source.h
@@ -18,7 +18,7 @@
namespace flightaware::uat {
class SoapySampleSource : public SampleSource {
public:
- static SampleSource::Pointer Create(boost::asio::io_service &service, const std::string &device_name, const boost::program_options::variables_map &options) { return Pointer(new SoapySampleSource(service, device_name, options)); }
+ static SampleSource::Pointer Create(boost::asio::io_context &service, const std::string &device_name, const boost::program_options::variables_map &options) { return Pointer(new SoapySampleSource(service, device_name, options)); }
virtual ~SoapySampleSource();
@@ -28,7 +28,7 @@ namespace flightaware::uat {
SampleFormat Format() override { return format_; }
private:
- SoapySampleSource(boost::asio::io_service &service, const std::string &device_name, const boost::program_options::variables_map &options);
+ SoapySampleSource(boost::asio::io_context &service, const std::string &device_name, const boost::program_options::variables_map &options);
void Run();
void Keepalive();
diff --git a/socket_input.cc b/socket_input.cc
index 64d2006..49b2d22 100644
--- a/socket_input.cc
+++ b/socket_input.cc
@@ -9,16 +9,16 @@ using boost::asio::ip::tcp;
#include <iostream>
-RawInput::RawInput(boost::asio::io_service &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval) : service_(service), host_(host), port_or_service_(port_or_service), reconnect_interval_(reconnect_interval), resolver_(service), socket_(service), reconnect_timer_(service), used_(0) { readbuf_.resize(8192); }
+RawInput::RawInput(boost::asio::io_context &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval) : service_(service), host_(host), port_or_service_(port_or_service), reconnect_interval_(reconnect_interval), resolver_(service), socket_(service), reconnect_timer_(service), used_(0) { readbuf_.resize(8192); }
void RawInput::Start() {
auto self(shared_from_this());
std::cerr << "Connecting to " << host_ << ":" << port_or_service_ << std::endl;
- tcp::resolver::query query(host_, port_or_service_);
- resolver_.async_resolve(query, [this, self](const boost::system::error_code &ec, tcp::resolver::iterator it) {
+ resolver_.async_resolve(host_, port_or_service_, [this, self](const boost::system::error_code &ec, tcp::resolver::results_type results) {
if (!ec) {
- next_endpoint_ = it;
+ endpoints_ = results;
+ next_endpoint_ = endpoints_.begin();
TryNextEndpoint(boost::asio::error::make_error_code(boost::asio::error::host_not_found));
} else if (ec == boost::asio::error::operation_aborted) {
return;
@@ -35,7 +35,7 @@ void RawInput::Stop() {
}
void RawInput::TryNextEndpoint(const boost::system::error_code &last_error) {
- if (next_endpoint_ == tcp::resolver::iterator()) {
+ if (next_endpoint_ == endpoints_.end()) {
// No more addresses to try
HandleError(last_error);
return;
@@ -92,7 +92,7 @@ void RawInput::HandleError(const boost::system::error_code &ec) {
auto self(shared_from_this());
- reconnect_timer_.expires_from_now(reconnect_interval_);
+ reconnect_timer_.expires_after(reconnect_interval_);
reconnect_timer_.async_wait([this, self](const boost::system::error_code &ec) {
if (!ec)
Start();
diff --git a/socket_input.h b/socket_input.h
index 774c81b..4fd4560 100644
--- a/socket_input.h
+++ b/socket_input.h
@@ -10,7 +10,7 @@
#include <memory>
#include <string>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/steady_timer.hpp>
@@ -22,7 +22,7 @@ namespace flightaware::uat {
typedef std::shared_ptr<RawInput> Pointer;
typedef std::function<void(const boost::system::error_code &)> ErrorHandler;
- static Pointer Create(boost::asio::io_service &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval = std::chrono::milliseconds(0)) { return Pointer(new RawInput(service, host, port_or_service, reconnect_interval)); }
+ static Pointer Create(boost::asio::io_context &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval = std::chrono::milliseconds(0)) { return Pointer(new RawInput(service, host, port_or_service, reconnect_interval)); }
void Start();
void Stop();
@@ -30,7 +30,7 @@ namespace flightaware::uat {
void SetErrorHandler(ErrorHandler handler) { error_handler_ = handler; }
private:
- RawInput(boost::asio::io_service &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval);
+ RawInput(boost::asio::io_context &service, const std::string &host, const std::string &port_or_service, std::chrono::milliseconds reconnect_interval);
void TryNextEndpoint(const boost::system::error_code &last_error);
void ScheduleRead();
@@ -39,14 +39,15 @@ namespace flightaware::uat {
boost::optional<RawMessage> ParseMetadataLine(const std::string &line);
void HandleError(const boost::system::error_code &ec);
- boost::asio::io_service &service_;
+ boost::asio::io_context &service_;
std::string host_;
std::string port_or_service_;
std::chrono::milliseconds reconnect_interval_;
boost::asio::ip::tcp::resolver resolver_;
boost::asio::ip::tcp::socket socket_;
- boost::asio::ip::tcp::resolver::iterator next_endpoint_;
+ boost::asio::ip::tcp::resolver::results_type endpoints_;
+ boost::asio::ip::tcp::resolver::results_type::iterator next_endpoint_;
boost::asio::steady_timer reconnect_timer_;
ErrorHandler error_handler_;
diff --git a/socket_output.cc b/socket_output.cc
index b2adbe3..a15fa97 100644
--- a/socket_output.cc
+++ b/socket_output.cc
@@ -6,7 +6,9 @@
#include <iostream>
#include <boost/asio.hpp>
+#include <boost/asio/post.hpp>
#include <boost/asio/ip/v6_only.hpp>
+#include <boost/asio/post.hpp>
#include "message_dispatch.h"
#include "socket_output.h"
@@ -16,7 +18,7 @@ using boost::asio::ip::tcp;
using namespace flightaware::uat;
-SocketOutput::SocketOutput(asio::io_service &service, tcp::socket &&socket) : service_(service), strand_(service), socket_(std::move(socket)), peer_(socket_.remote_endpoint()), flush_pending_(false) {}
+SocketOutput::SocketOutput(asio::io_context &service, tcp::socket &&socket) : service_(service), strand_(service), socket_(std::move(socket)), peer_(socket_.remote_endpoint()), flush_pending_(false) {}
void SocketOutput::Start() { ReadAndDiscard(); }
@@ -34,7 +36,7 @@ void SocketOutput::ReadAndDiscard() {
void SocketOutput::Write(SharedMessageVector messages) {
auto self(shared_from_this());
- strand_.dispatch([this, self, messages]() {
+ boost::asio::dispatch(strand_, [this, self, messages]() {
if (IsOpen()) {
InternalWrite(messages);
Flush();
@@ -108,7 +110,7 @@ void JsonOutput::InternalWrite(SharedMessageVector messages) {
//////////////
-SocketListener::SocketListener(asio::io_service &service, const tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory) : service_(service), acceptor_(service), endpoint_(endpoint), socket_(service), dispatch_(dispatch), factory_(factory) {}
+SocketListener::SocketListener(asio::io_context &service, const tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory) : service_(service), acceptor_(service), endpoint_(endpoint), socket_(service), dispatch_(dispatch), factory_(factory) {}
void SocketListener::Start() {
acceptor_.open(endpoint_.protocol());
diff --git a/socket_output.h b/socket_output.h
index 32c842e..24b7751 100644
--- a/socket_output.h
+++ b/socket_output.h
@@ -10,7 +10,7 @@
#include <memory>
#include <sstream>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/strand.hpp>
@@ -31,7 +31,7 @@ namespace flightaware::uat {
bool IsOpen() const { return socket_.is_open(); }
protected:
- SocketOutput(boost::asio::io_service &service_, boost::asio::ip::tcp::socket &&socket_);
+ SocketOutput(boost::asio::io_context &service_, boost::asio::ip::tcp::socket &&socket_);
std::ostringstream &Buf() { return outbuf_; }
virtual void InternalWrite(SharedMessageVector messages) = 0;
@@ -41,8 +41,8 @@ namespace flightaware::uat {
void Flush();
void ReadAndDiscard();
- boost::asio::io_service &service_;
- boost::asio::io_service::strand strand_;
+ boost::asio::io_context &service_;
+ boost::asio::io_context::strand strand_;
boost::asio::ip::tcp::socket socket_;
boost::asio::ip::tcp::endpoint peer_;
@@ -55,7 +55,7 @@ namespace flightaware::uat {
class RawOutput : public SocketOutput {
public:
// factory method, this class must always be constructed via make_shared
- static Pointer Create(boost::asio::io_service &service, boost::asio::ip::tcp::socket &&socket, SharedMessageVector header) { return Pointer(new RawOutput(service, std::move(socket), header)); }
+ static Pointer Create(boost::asio::io_context &service, boost::asio::ip::tcp::socket &&socket, SharedMessageVector header) { return Pointer(new RawOutput(service, std::move(socket), header)); }
void Start() override;
@@ -63,7 +63,7 @@ namespace flightaware::uat {
void InternalWrite(SharedMessageVector messages) override;
private:
- RawOutput(boost::asio::io_service &service_, boost::asio::ip::tcp::socket &&socket_, SharedMessageVector header) : SocketOutput(service_, std::move(socket_)) { header_ = header; }
+ RawOutput(boost::asio::io_context &service_, boost::asio::ip::tcp::socket &&socket_, SharedMessageVector header) : SocketOutput(service_, std::move(socket_)) { header_ = header; }
SharedMessageVector header_;
};
@@ -71,32 +71,32 @@ namespace flightaware::uat {
class JsonOutput : public SocketOutput {
public:
// factory method, this class must always be constructed via make_shared
- static Pointer Create(boost::asio::io_service &service, boost::asio::ip::tcp::socket &&socket) { return Pointer(new JsonOutput(service, std::move(socket))); }
+ static Pointer Create(boost::asio::io_context &service, boost::asio::ip::tcp::socket &&socket) { return Pointer(new JsonOutput(service, std::move(socket))); }
protected:
void InternalWrite(SharedMessageVector messages) override;
private:
- JsonOutput(boost::asio::io_service &service_, boost::asio::ip::tcp::socket &&socket_) : SocketOutput(service_, std::move(socket_)) {}
+ JsonOutput(boost::asio::io_context &service_, boost::asio::ip::tcp::socket &&socket_) : SocketOutput(service_, std::move(socket_)) {}
};
class SocketListener : public std::enable_shared_from_this<SocketListener> {
public:
typedef std::shared_ptr<SocketListener> Pointer;
- typedef std::function<SocketOutput::Pointer(boost::asio::io_service &, boost::asio::ip::tcp::socket &&)> ConnectionFactory;
+ typedef std::function<SocketOutput::Pointer(boost::asio::io_context &, boost::asio::ip::tcp::socket &&)> ConnectionFactory;
// factory method, this class must always be constructed via make_shared
- static Pointer Create(boost::asio::io_service &service, const boost::asio::ip::tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory) { return Pointer(new SocketListener(service, endpoint, dispatch, factory)); }
+ static Pointer Create(boost::asio::io_context &service, const boost::asio::ip::tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory) { return Pointer(new SocketListener(service, endpoint, dispatch, factory)); }
void Start();
void Close();
private:
- SocketListener(boost::asio::io_service &service, const boost::asio::ip::tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory);
+ SocketListener(boost::asio::io_context &service, const boost::asio::ip::tcp::endpoint &endpoint, MessageDispatch &dispatch, ConnectionFactory factory);
void Accept();
- boost::asio::io_service &service_;
+ boost::asio::io_context &service_;
boost::asio::ip::tcp::acceptor acceptor_;
boost::asio::ip::tcp::endpoint endpoint_;
boost::asio::ip::tcp::socket socket_;
diff --git a/stratux_serial.cc b/stratux_serial.cc
index 249d797..a6cae57 100644
--- a/stratux_serial.cc
+++ b/stratux_serial.cc
@@ -34,7 +34,7 @@ enum class StratuxSerial::ParserState {
MESSAGE // reading rssi / timestamp / payload
};
-StratuxSerial::StratuxSerial(boost::asio::io_service &io_service, const std::string &path) : io_service_(io_service), path_(path), port_(io_service), read_timer_(io_service), parser_state_(ParserState::PREAMBLE), preamble_index_(0) {}
+StratuxSerial::StratuxSerial(boost::asio::io_context &io_service, const std::string &path) : io_context_(io_service), path_(path), port_(io_service), read_timer_(io_service), parser_state_(ParserState::PREAMBLE), preamble_index_(0) {}
void StratuxSerial::Start() {
try {
@@ -95,7 +95,7 @@ void StratuxSerial::StartReading() {
// little more data arrives, but at least we don't have to do a bunch of work on every one of
// those)
if (len < read_buffer_size * 3 / 4) {
- read_timer_.expires_from_now(read_interval);
+ read_timer_.expires_after(read_interval);
read_timer_.async_wait([this, self](const boost::system::error_code &ec) {
if (!ec) {
StartReading();
diff --git a/stratux_serial.h b/stratux_serial.h
index 2d290bd..19809f7 100644
--- a/stratux_serial.h
+++ b/stratux_serial.h
@@ -12,7 +12,7 @@
#include <functional>
#include <memory>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/serial_port.hpp>
#include <boost/asio/steady_timer.hpp>
@@ -32,10 +32,10 @@ namespace flightaware::uat {
virtual void Start();
virtual void Stop();
- static Pointer Create(boost::asio::io_service &io_service, const std::string &path) { return Pointer(new StratuxSerial(io_service, path)); }
+ static Pointer Create(boost::asio::io_context &io_service, const std::string &path) { return Pointer(new StratuxSerial(io_service, path)); }
protected:
- StratuxSerial(boost::asio::io_service &io_service, const std::string &path);
+ StratuxSerial(boost::asio::io_context &io_service, const std::string &path);
private:
void StartReading();
@@ -48,7 +48,7 @@ namespace flightaware::uat {
// how long to wait between scheduling reads (to reduce the spinning on short messages)
const std::chrono::milliseconds read_interval = std::chrono::milliseconds(50);
- boost::asio::io_service &io_service_;
+ boost::asio::io_context &io_context_;
std::string path_;
boost::asio::serial_port port_;
boost::asio::steady_timer read_timer_;
diff --git a/track.cc b/track.cc
index f2e319e..c01c298 100644
--- a/track.cc
+++ b/track.cc
@@ -121,7 +121,7 @@ void Tracker::PurgeOld() {
}
}
auto self(shared_from_this());
- timer_.expires_from_now(timeout_ / 4);
+ timer_.expires_after(timeout_ / 4);
timer_.async_wait(strand_.wrap([this, self](const boost::system::error_code &ec) {
if (!ec) {
PurgeOld();
@@ -134,7 +134,7 @@ void Tracker::HandleMessages(SharedMessageVector messages) {
const std::uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - unix_epoch).count();
auto self(shared_from_this());
- strand_.dispatch([this, self, now, messages]() {
+ boost::asio::dispatch(strand_, [this, self, now, messages]() {
const std::uint64_t PAST_FUZZ = 15000;
const std::uint64_t FUTURE_FUZZ = 1000;
diff --git a/track.h b/track.h
index 968ec7d..5d65b8c 100644
--- a/track.h
+++ b/track.h
@@ -12,7 +12,7 @@
#include <numeric>
#include <array>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/strand.hpp>
@@ -146,7 +146,7 @@ namespace flightaware::uat {
typedef std::shared_ptr<Tracker> Pointer;
typedef std::map<AddressKey, AircraftState> MapType;
- static Pointer Create(boost::asio::io_service &service, std::chrono::milliseconds timeout = std::chrono::seconds(300)) { return Pointer(new Tracker(service, timeout)); }
+ static Pointer Create(boost::asio::io_context &service, std::chrono::milliseconds timeout = std::chrono::seconds(300)) { return Pointer(new Tracker(service, timeout)); }
void Start();
void Stop();
@@ -158,12 +158,12 @@ namespace flightaware::uat {
void PurgeOld();
private:
- Tracker(boost::asio::io_service &service, std::chrono::milliseconds timeout) : service_(service), strand_(service), timer_(service), timeout_(timeout) {}
+ Tracker(boost::asio::io_context &service, std::chrono::milliseconds timeout) : service_(service), strand_(service), timer_(service), timeout_(timeout) {}
void HandleMessage(const AdsbMessage &message);
- boost::asio::io_service &service_;
- boost::asio::io_service::strand strand_;
+ boost::asio::io_context &service_;
+ boost::asio::io_context::strand strand_;
boost::asio::steady_timer timer_;
std::chrono::milliseconds timeout_;
MapType aircraft_;
|