GobySoft/goby3

boost 1.75

Closed this issue · 5 comments

Have you tested out to boost 1.75 yet? I see in asio-compat.h that there are some references to changes to ASIO around version 1.7.

I'm seeing these messages:

../include/goby/acomms/modemdriver/iridium_shore_rudics.h:113:81: error: no matching function for call to ‘boost::asio::basic_stream_socket<boost::asio::ip::tcp>::basic_stream_socket(const boost::asio::executor&)’
  113 |         : socket_(executor), remote_endpoint_str_("Unknown"), packet_failures_(0)

and

/usr/include/boost/asio/impl/executor.hpp:104:15: error: ‘class boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0> > >’ has no member named ‘defer’; did you mean ‘prefer’?
  104 |     executor_.defer(BOOST_ASIO_MOVE_CAST(function)(f), allocator_);

I think this is a workaround:

  • bump the boost version in asio-compat.h so that 1.75 gets the io_service
  • use this macro to fix get_io_service():
#if BOOST_VERSION >= 107000
#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
#else
#define GET_IO_SERVICE(s) ((s).get_io_service())
#endif

Thanks, I haven't tried 1.75 yet, though I wish ASIO would stop messing around with their API seemingly every release.

If you have a working workaround, please put up a pull request.

Thanks!
-Toby

I'm still testing it, but here is the possible patch:

diff --git a/src/acomms/modemdriver/iridium_shore_rudics.h b/src/acomms/modemdriver/iridium_shore_rudics.h
index a888820..94880c9 100644
--- a/src/acomms/modemdriver/iridium_shore_rudics.h
+++ b/src/acomms/modemdriver/iridium_shore_rudics.h
@@ -185,7 +185,7 @@
     {
         std::shared_ptr<RUDICSConnection> new_connection =
 #ifdef USE_BOOST_IO_SERVICE
-            RUDICSConnection::create(acceptor_.get_io_service());
+            RUDICSConnection::create(GET_IO_SERVICE(acceptor_));
 #else
             RUDICSConnection::create(acceptor_.get_executor());
 #endif
diff --git a/src/acomms/modemdriver/iridium_shore_sbd.h b/src/acomms/modemdriver/iridium_shore_sbd.h
index ab63250..70c10c1 100644
--- a/src/acomms/modemdriver/iridium_shore_sbd.h
+++ b/src/acomms/modemdriver/iridium_shore_sbd.h
@@ -265,7 +265,7 @@
     {
         std::shared_ptr<SBDConnection> new_connection =
 #ifdef USE_BOOST_IO_SERVICE
-            SBDConnection::create(acceptor_.get_io_service());
+            SBDConnection::create(GET_IO_SERVICE(acceptor_));
 #else
             SBDConnection::create(acceptor_.get_executor());
 #endif
diff --git a/src/util/asio-compat.h b/src/util/asio-compat.h
index 0c9fef4..a5fc01c 100644
--- a/src/util/asio-compat.h
+++ b/src/util/asio-compat.h
@@ -28,11 +28,17 @@
 #include <boost/version.hpp>
 
 // manage the switch from ASIO io_service to io_context introduced in Boost 1.66 but functions were not reworked until 1.70
-#if BOOST_VERSION < 107000
+#if BOOST_VERSION <= 107500
 #include <boost/asio/io_service.hpp>
 #define USE_BOOST_IO_SERVICE
 #endif
 
+#if BOOST_VERSION >= 107000
+#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
+#else
+#define GET_IO_SERVICE(s) ((s).get_io_service())
+#endif
+
 // also typedef new names
 #if BOOST_VERSION < 106600
 namespace boost
diff --git a/src/util/linebasedcomms/tcp_server.h b/src/util/linebasedcomms/tcp_server.h
index 63e2a7d..f691922 100644
--- a/src/util/linebasedcomms/tcp_server.h
+++ b/src/util/linebasedcomms/tcp_server.h
@@ -112,7 +112,7 @@
     void start()
     {
 #ifdef USE_BOOST_IO_SERVICE
-        socket_.get_io_service().post(boost::bind(&TCPConnection::read_start, this));
+        GET_IO_SERVICE(socket_).post(boost::bind(&TCPConnection::read_start, this));
 #else
         boost::asio::post(socket_.get_executor(), boost::bind(&TCPConnection::read_start, this));
 #endif
@@ -121,7 +121,7 @@
     void write(const protobuf::Datagram& msg)
     {
 #ifdef USE_BOOST_IO_SERVICE
-        socket_.get_io_service().post(boost::bind(&TCPConnection::socket_write, this, msg));
+        GET_IO_SERVICE(socket_).post(boost::bind(&TCPConnection::socket_write, this, msg));
 #else
         boost::asio::post(socket_.get_executor(),
                           boost::bind(&TCPConnection::socket_write, this, msg));
@@ -131,7 +131,7 @@
     void close(const boost::system::error_code& error)
     {
 #ifdef USE_BOOST_IO_SERVICE
-        socket_.get_io_service().post(boost::bind(&TCPConnection::socket_close, this, error));
+        GET_IO_SERVICE(socket_).post(boost::bind(&TCPConnection::socket_close, this, error));
 #else
         boost::asio::post(socket_.get_executor(),
                           boost::bind(&TCPConnection::socket_close, this, error));

This simpler patch seems to do it:

diff --git a/src/acomms/modemdriver/iridium_shore_rudics.h b/src/acomms/modemdriver/iridium_shore_rudics.h
index a3eb03da..737d46aa 100644
--- a/src/acomms/modemdriver/iridium_shore_rudics.h
+++ b/src/acomms/modemdriver/iridium_shore_rudics.h
@@ -45,7 +45,7 @@ class RUDICSConnection : public std::enable_shared_from_this<RUDICSConnection>
 #ifdef USE_BOOST_IO_SERVICE
         boost::asio::io_service& executor)
 #else
-        const boost::asio::executor& executor)
+        const boost::asio::ip::tcp::socket::executor_type& executor)
 #endif
     {
         return std::shared_ptr<RUDICSConnection>(new RUDICSConnection(executor));
@@ -109,7 +109,7 @@ class RUDICSConnection : public std::enable_shared_from_this<RUDICSConnection>
 #ifdef USE_BOOST_IO_SERVICE
         boost::asio::io_service& executor)
 #else
-        const boost::asio::executor& executor)
+        const boost::asio::ip::tcp::socket::executor_type& executor)
 #endif
         : socket_(executor), remote_endpoint_str_("Unknown"), packet_failures_(0)
     {
diff --git a/src/acomms/modemdriver/iridium_shore_sbd.h b/src/acomms/modemdriver/iridium_shore_sbd.h
index 14832f37..52b23f2b 100644
--- a/src/acomms/modemdriver/iridium_shore_sbd.h
+++ b/src/acomms/modemdriver/iridium_shore_sbd.h
@@ -207,7 +207,7 @@ class SBDConnection : public boost::enable_shared_from_this<SBDConnection>
 #ifdef USE_BOOST_IO_SERVICE
         boost::asio::io_service& executor)
 #else
-        const boost::asio::executor& executor)
+        const boost::asio::ip::tcp::socket::executor_type& executor)
 #endif
     {
         return std::shared_ptr<SBDConnection>(new SBDConnection(executor));
@@ -238,7 +238,7 @@ class SBDConnection : public boost::enable_shared_from_this<SBDConnection>
 #ifdef USE_BOOST_IO_SERVICE
         boost::asio::io_service& executor)
 #else
-        const boost::asio::executor& executor)
+        const boost::asio::ip::tcp::socket::executor_type& executor)
 #endif
         : socket_(executor), connect_time_(-1), message_(socket_), remote_endpoint_str_("Unknown")
     {

Fixed in #229