Prefer `asio::io_context` over `asio::io_service`
Change-Id: I08f136b49e0f03e30d26803be030497ec22eb01f
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();