Prefer `asio::io_context` over `asio::io_service`
Change-Id: I08f136b49e0f03e30d26803be030497ec22eb01f
diff --git a/examples/data-producer.cpp b/examples/data-producer.cpp
index 0e1da2c..2a23e9c 100644
--- a/examples/data-producer.cpp
+++ b/examples/data-producer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -34,7 +34,7 @@
* The description of command parameter can be found in the function usage().
*/
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/lexical_cast.hpp>
#include <ndn-cxx/data.hpp>
@@ -49,11 +49,7 @@
#include <random>
#include <string>
-namespace repo {
-
-using ndn::time::milliseconds;
-
-const milliseconds DEFAULT_TIME_INTERVAL(2000);
+namespace repo::examples {
enum Mode {
AUTO,
@@ -70,16 +66,6 @@
};
public:
- Publisher()
- : mode(AUTO)
- , dataPrefix("/example/data")
- , timeInterval(DEFAULT_TIME_INTERVAL)
- , duration(0)
- , m_scheduler(m_face.getIoService())
- , m_randomDist(200, 1000)
- {
- }
-
void
run();
@@ -94,15 +80,15 @@
public:
std::ifstream insertStream;
- Mode mode;
- ndn::Name dataPrefix;
- milliseconds timeInterval;
- milliseconds duration;
+ Mode mode{AUTO};
+ ndn::Name dataPrefix{"/example/data"};
+ ndn::time::milliseconds timeInterval{2000};
+ ndn::time::milliseconds duration{0};
private:
ndn::Face m_face;
- ndn::Scheduler m_scheduler;
- std::uniform_int_distribution<> m_randomDist;
+ ndn::Scheduler m_scheduler{m_face.getIoService()};
+ std::uniform_int_distribution<> m_randomDist{200, 1000};
};
void
@@ -199,7 +185,7 @@
break;
case 's':
try {
- generator.duration = milliseconds(boost::lexical_cast<uint64_t>(optarg));
+ generator.duration = ndn::time::milliseconds(boost::lexical_cast<uint64_t>(optarg));
}
catch (const boost::bad_lexical_cast&) {
std::cerr << "-s option should be an integer" << std::endl;
@@ -208,7 +194,7 @@
break;
case 't':
try {
- generator.timeInterval = milliseconds(boost::lexical_cast<uint64_t>(optarg));
+ generator.timeInterval = ndn::time::milliseconds(boost::lexical_cast<uint64_t>(optarg));
}
catch (const boost::bad_lexical_cast&) {
std::cerr << "-t option should be an integer" << std::endl;
@@ -234,13 +220,13 @@
return 0;
}
-} // namespace repo
+} // namespace repo::examples
int
main(int argc, char* argv[])
{
try {
- return repo::main(argc, argv);
+ return repo::examples::main(argc, argv);
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
diff --git a/src/handles/tcp-bulk-insert-handle.cpp b/src/handles/tcp-bulk-insert-handle.cpp
index dc4042d..2713d03 100644
--- a/src/handles/tcp-bulk-insert-handle.cpp
+++ b/src/handles/tcp-bulk-insert-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -20,6 +20,7 @@
#include "tcp-bulk-insert-handle.hpp"
#include <boost/asio/ip/v6_only.hpp>
+
#include <ndn-cxx/util/logger.hpp>
NDN_LOG_INIT(repo.TcpHandle);
@@ -62,9 +63,9 @@
} // namespace detail
-TcpBulkInsertHandle::TcpBulkInsertHandle(boost::asio::io_service& ioService,
+TcpBulkInsertHandle::TcpBulkInsertHandle(boost::asio::io_context& io,
RepoStorage& storageHandle)
- : m_acceptor(ioService)
+ : m_acceptor(io)
, m_storageHandle(storageHandle)
{
}
@@ -72,18 +73,11 @@
void
TcpBulkInsertHandle::listen(const std::string& host, const std::string& port)
{
- ip::tcp::resolver resolver(m_acceptor
-#if BOOST_VERSION >= 107000
- .get_executor()
-#else
- .get_io_service()
-#endif
- );
+ ip::tcp::resolver resolver(m_acceptor.get_executor());
ip::tcp::resolver::query query(host, port);
ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
ip::tcp::resolver::iterator end;
-
if (endpoint == end)
NDN_THROW(Error("Cannot listen on " + host + " port " + port));
@@ -111,13 +105,7 @@
void
TcpBulkInsertHandle::asyncAccept()
{
- auto clientSocket = std::make_shared<ip::tcp::socket>(m_acceptor
-#if BOOST_VERSION >= 107000
- .get_executor()
-#else
- .get_io_service()
-#endif
- );
+ auto clientSocket = std::make_shared<ip::tcp::socket>(m_acceptor.get_executor());
m_acceptor.async_accept(*clientSocket,
std::bind(&TcpBulkInsertHandle::handleAccept, this, _1, clientSocket));
}
diff --git a/src/handles/tcp-bulk-insert-handle.hpp b/src/handles/tcp-bulk-insert-handle.hpp
index 2930985..a0a8e7a 100644
--- a/src/handles/tcp-bulk-insert-handle.hpp
+++ b/src/handles/tcp-bulk-insert-handle.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -37,8 +37,7 @@
};
public:
- TcpBulkInsertHandle(boost::asio::io_service& ioService,
- RepoStorage& storageHandle);
+ TcpBulkInsertHandle(boost::asio::io_context& io, RepoStorage& storageHandle);
void
listen(const std::string& host, const std::string& port);
diff --git a/src/main.cpp b/src/main.cpp
index 767dc8f..ad0dd67 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2018-2022, Regents of the University of California.
+ * Copyright (c) 2018-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -24,7 +24,7 @@
#include <iostream>
#include <string.h> // for strsignal()
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/program_options.hpp>
@@ -66,24 +66,24 @@
return 0;
}
- boost::asio::io_service ioService;
+ boost::asio::io_context ioCtx;
/// \todo reload config file on SIGHUP
- boost::asio::signal_set signalSet(ioService, SIGINT, SIGTERM);
- signalSet.async_wait([&ioService] (const boost::system::error_code& error, int signalNo) {
+ boost::asio::signal_set signalSet(ioCtx, SIGINT, SIGTERM);
+ signalSet.async_wait([&ioCtx] (const boost::system::error_code& error, int signalNo) {
if (!error) {
NDN_LOG_FATAL("Exiting on signal " << signalNo << "/" << strsignal(signalNo));
- ioService.stop();
+ ioCtx.stop();
}
});
try {
- repo::Repo repo(ioService, repo::parseConfig(configFile));
+ repo::Repo repo(ioCtx, repo::parseConfig(configFile));
repo.initializeStorage();
repo.enableValidation();
repo.enableListening();
- ioService.run();
+ ioCtx.run();
}
catch (const std::exception& e) {
NDN_LOG_FATAL(repo::getExtendedErrorMessage(e));
diff --git a/src/repo.cpp b/src/repo.cpp
index 8ee393f..acc83bd 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -106,10 +106,10 @@
return repoConfig;
}
-Repo::Repo(boost::asio::io_service& ioService, const RepoConfig& config)
+Repo::Repo(boost::asio::io_context& io, const RepoConfig& config)
: m_config(config)
- , m_scheduler(ioService)
- , m_face(ioService)
+ , m_scheduler(io)
+ , m_face(io)
, m_dispatcher(m_face, m_keyChain)
, m_store(std::make_shared<SqliteStorage>(config.dbPath))
, m_storageHandle(*m_store)
@@ -117,7 +117,7 @@
, m_readHandle(m_face, m_storageHandle, m_config.registrationSubset)
, m_writeHandle(m_face, m_storageHandle, m_dispatcher, m_scheduler, m_validator)
, m_deleteHandle(m_face, m_storageHandle, m_dispatcher, m_scheduler, m_validator)
- , m_tcpBulkInsertHandle(ioService, m_storageHandle)
+ , m_tcpBulkInsertHandle(io, m_storageHandle)
{
this->enableValidation();
m_storageHandle.notifyAboutExistingData();
diff --git a/src/repo.hpp b/src/repo.hpp
index 9b7630e..68f339f 100644
--- a/src/repo.hpp
+++ b/src/repo.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -66,9 +66,9 @@
};
public:
- Repo(boost::asio::io_service& ioService, const RepoConfig& config);
+ Repo(boost::asio::io_context& io, const RepoConfig& config);
- //@brief rebuild index from storage file when repo starts.
+ /// @brief Rebuild index from storage file when repo starts.
void
initializeStorage();
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index ed62466..56d1393 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -24,7 +24,7 @@
#include "../repo-storage-fixture.hpp"
#include "../dataset-fixtures.hpp"
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
#include <boost/test/unit_test.hpp>
namespace repo::tests {
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index 9b7b796..2c6a32e 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -31,11 +31,6 @@
class TcpClient
{
public:
- TcpClient()
- : socket(ioService)
- {
- }
-
virtual
~TcpClient() = default;
@@ -44,7 +39,7 @@
{
using namespace boost::asio;
- ip::tcp::resolver resolver(ioService);
+ ip::tcp::resolver resolver(ioCtx);
ip::tcp::resolver::query query(host, port);
ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
@@ -69,8 +64,8 @@
}
public:
- boost::asio::io_service ioService;
- boost::asio::ip::tcp::socket socket;
+ boost::asio::io_context ioCtx;
+ boost::asio::ip::tcp::socket socket{ioCtx};
};
template<class Dataset>
@@ -80,8 +75,8 @@
{
public:
TcpBulkInsertFixture()
- : scheduler(ioService)
- , bulkInserter(ioService, *handle)
+ : scheduler(ioCtx)
+ , bulkInserter(ioCtx, *handle)
{
guardEvent = scheduler.schedule(2_s, std::bind(&TcpBulkInsertFixture::fail, this, "Test timed out"));
}
@@ -125,7 +120,7 @@
void
fail(const std::string& info)
{
- ioService.stop();
+ ioCtx.stop();
BOOST_FAIL(info);
}
@@ -137,7 +132,7 @@
socket.close();
bulkInserter.stop();
- // may be ioService.stop() as well
+ // may be ioCtx.stop() as well
}
public:
@@ -155,7 +150,7 @@
this->start("localhost", "17376");
// actually run the test
- this->ioService.run();
+ this->ioCtx.run();
// Read (all items should exist)
for (auto i = this->interests.begin(); i != this->interests.end(); ++i) {