From 87ee31f88d82169a85fade8d91e9469d9d508d5e Mon Sep 17 00:00:00 2001
From: Adam Emerson <aemerson@redhat.com>
Date: Fri, 13 Dec 2024 15:21:49 -0500
Subject: [PATCH] immutable_object_cache: Asio deprecations

Signed-off-by: Adam Emerson <aemerson@redhat.com>
---
 src/tools/immutable_object_cache/CacheClient.cc |  6 +++---
 src/tools/immutable_object_cache/CacheClient.h  |  5 +++--
 src/tools/immutable_object_cache/CacheServer.cc | 10 +++++-----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/tools/immutable_object_cache/CacheClient.cc b/src/tools/immutable_object_cache/CacheClient.cc
index 44686529547d3..32a199dbe2102 100644
--- a/src/tools/immutable_object_cache/CacheClient.cc
+++ b/src/tools/immutable_object_cache/CacheClient.cc
@@ -20,7 +20,7 @@ namespace ceph {
 namespace immutable_obj_cache {
 
   CacheClient::CacheClient(const std::string& file, CephContext* ceph_ctx)
-    : m_cct(ceph_ctx), m_io_service_work(m_io_service),
+    : m_cct(ceph_ctx), m_io_service_work(m_io_service.get_executor()),
       m_dm_socket(m_io_service), m_ep(stream_protocol::endpoint(file)),
       m_io_thread(nullptr), m_session_work(false), m_writing(false),
       m_reading(false), m_sequence_id(0) {
@@ -30,7 +30,7 @@ namespace immutable_obj_cache {
 
     if (m_worker_thread_num != 0) {
       m_worker = new boost::asio::io_context();
-      m_worker_io_service_work = new boost::asio::io_context::work(*m_worker);
+      m_worker_io_service_work = new boost::asio::executor_work_guard<boost::asio::io_context::executor_type>(m_worker->get_executor());
       for (uint64_t i = 0; i < m_worker_thread_num; i++) {
         std::thread* thd = new std::thread([this](){m_worker->run();});
         m_worker_threads.push_back(thd);
@@ -299,7 +299,7 @@ namespace immutable_obj_cache {
     });
 
     if (m_worker_thread_num != 0) {
-      m_worker->post([process_reply]() {
+      boost::asio::post(*m_worker, [process_reply]() {
         process_reply->complete(true);
       });
     } else {
diff --git a/src/tools/immutable_object_cache/CacheClient.h b/src/tools/immutable_object_cache/CacheClient.h
index 7dc4aa76c1324..5122e0906b91b 100644
--- a/src/tools/immutable_object_cache/CacheClient.h
+++ b/src/tools/immutable_object_cache/CacheClient.h
@@ -5,6 +5,7 @@
 #define CEPH_CACHE_CACHE_CLIENT_H
 
 #include <atomic>
+#include <boost/asio/executor_work_guard.hpp>
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/local/stream_protocol.hpp>
 #include <boost/algorithm/string.hpp>
@@ -58,7 +59,7 @@ class CacheClient {
  private:
   CephContext* m_cct;
   boost::asio::io_context m_io_service;
-  boost::asio::io_context::work m_io_service_work;
+  boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_io_service_work;
   stream_protocol::socket m_dm_socket;
   stream_protocol::endpoint m_ep;
   std::shared_ptr<std::thread> m_io_thread;
@@ -67,7 +68,7 @@ class CacheClient {
   uint64_t m_worker_thread_num;
   boost::asio::io_context* m_worker;
   std::vector<std::thread*> m_worker_threads;
-  boost::asio::io_context::work* m_worker_io_service_work;
+  boost::asio::executor_work_guard<boost::asio::io_context::executor_type>* m_worker_io_service_work;
 
   std::atomic<bool> m_writing;
   std::atomic<bool> m_reading;
diff --git a/src/tools/immutable_object_cache/CacheServer.cc b/src/tools/immutable_object_cache/CacheServer.cc
index 14deddce561b3..a4c4e3bc36ce1 100644
--- a/src/tools/immutable_object_cache/CacheServer.cc
+++ b/src/tools/immutable_object_cache/CacheServer.cc
@@ -35,10 +35,10 @@ int CacheServer::run() {
     return ret;
   }
 
-  boost::system::error_code ec;
-  ret = m_io_service.run(ec);
-  if (ec) {
-    ldout(cct, 1) << "m_io_service run fails: " << ec.message() << dendl;
+  try {
+    ret = m_io_service.run();
+  } catch (const std::exception& e) {
+    ldout(cct, 1) << "m_io_service run fails: " << e.what() << dendl;
     return -1;
   }
   return 0;
@@ -66,7 +66,7 @@ int CacheServer::start_accept() {
     return -ec.value();
   }
 
-  m_acceptor.listen(boost::asio::socket_base::max_connections, ec);
+  m_acceptor.listen(boost::asio::socket_base::max_listen_connections, ec);
   if (ec) {
     lderr(cct) << "failed to listen on domain socket: " << ec.message()
                << dendl;
