diff options
Diffstat (limited to '3rdparty/asio/src/examples/cpp14')
39 files changed, 1072 insertions, 171 deletions
diff --git a/3rdparty/asio/src/examples/cpp14/Makefile.am b/3rdparty/asio/src/examples/cpp14/Makefile.am index 50aca20a357..2ddf12a8a2f 100644 --- a/3rdparty/asio/src/examples/cpp14/Makefile.am +++ b/3rdparty/asio/src/examples/cpp14/Makefile.am @@ -32,6 +32,9 @@ noinst_PROGRAMS = \ executors/pipeline \ executors/priority_scheduler \ iostreams/http_client \ + operations/c_callback_wrapper \ + operations/callback_wrapper \ + operations/composed_1 \ operations/composed_1 \ operations/composed_2 \ operations/composed_3 \ @@ -41,6 +44,7 @@ noinst_PROGRAMS = \ operations/composed_7 \ operations/composed_8 \ parallel_group/parallel_sort \ + parallel_group/ranged_wait_for_all \ parallel_group/wait_for_all \ parallel_group/wait_for_one \ parallel_group/wait_for_one_error \ @@ -70,6 +74,8 @@ executors_fork_join_SOURCES = executors/fork_join.cpp executors_pipeline_SOURCES = executors/pipeline.cpp executors_priority_scheduler_SOURCES = executors/priority_scheduler.cpp iostreams_http_client_SOURCES = iostreams/http_client.cpp +operations_c_callback_wrapper_SOURCES = operations/c_callback_wrapper.cpp +operations_callback_wrapper_SOURCES = operations/callback_wrapper.cpp operations_composed_1_SOURCES = operations/composed_1.cpp operations_composed_2_SOURCES = operations/composed_2.cpp operations_composed_3_SOURCES = operations/composed_3.cpp @@ -79,6 +85,7 @@ operations_composed_6_SOURCES = operations/composed_6.cpp operations_composed_7_SOURCES = operations/composed_7.cpp operations_composed_8_SOURCES = operations/composed_8.cpp parallel_group_parallel_sort_SOURCES = parallel_group/parallel_sort.cpp +parallel_group_ranged_wait_for_all_SOURCES = parallel_group/ranged_wait_for_all.cpp parallel_group_wait_for_all_SOURCES = parallel_group/wait_for_all.cpp parallel_group_wait_for_one_SOURCES = parallel_group/wait_for_one.cpp parallel_group_wait_for_one_error_SOURCES = parallel_group/wait_for_one_error.cpp diff --git a/3rdparty/asio/src/examples/cpp14/Makefile.in b/3rdparty/asio/src/examples/cpp14/Makefile.in index a6e79dc8e7e..23fdb3fc1e2 100644 --- a/3rdparty/asio/src/examples/cpp14/Makefile.in +++ b/3rdparty/asio/src/examples/cpp14/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.1 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2018 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -105,12 +105,16 @@ noinst_PROGRAMS = deferred/deferred_1$(EXEEXT) \ executors/bank_account_2$(EXEEXT) executors/fork_join$(EXEEXT) \ executors/pipeline$(EXEEXT) \ executors/priority_scheduler$(EXEEXT) \ - iostreams/http_client$(EXEEXT) operations/composed_1$(EXEEXT) \ + iostreams/http_client$(EXEEXT) \ + operations/c_callback_wrapper$(EXEEXT) \ + operations/callback_wrapper$(EXEEXT) \ + operations/composed_1$(EXEEXT) operations/composed_1$(EXEEXT) \ operations/composed_2$(EXEEXT) operations/composed_3$(EXEEXT) \ operations/composed_4$(EXEEXT) operations/composed_5$(EXEEXT) \ operations/composed_6$(EXEEXT) operations/composed_7$(EXEEXT) \ operations/composed_8$(EXEEXT) \ parallel_group/parallel_sort$(EXEEXT) \ + parallel_group/ranged_wait_for_all$(EXEEXT) \ parallel_group/wait_for_all$(EXEEXT) \ parallel_group/wait_for_one$(EXEEXT) \ parallel_group/wait_for_one_error$(EXEEXT) \ @@ -266,6 +270,20 @@ iostreams_http_client_OBJECTS = $(am_iostreams_http_client_OBJECTS) iostreams_http_client_LDADD = $(LDADD) @SEPARATE_COMPILATION_TRUE@iostreams_http_client_DEPENDENCIES = \ @SEPARATE_COMPILATION_TRUE@ libasio.a +am_operations_c_callback_wrapper_OBJECTS = \ + operations/c_callback_wrapper.$(OBJEXT) +operations_c_callback_wrapper_OBJECTS = \ + $(am_operations_c_callback_wrapper_OBJECTS) +operations_c_callback_wrapper_LDADD = $(LDADD) +@SEPARATE_COMPILATION_TRUE@operations_c_callback_wrapper_DEPENDENCIES = \ +@SEPARATE_COMPILATION_TRUE@ libasio.a +am_operations_callback_wrapper_OBJECTS = \ + operations/callback_wrapper.$(OBJEXT) +operations_callback_wrapper_OBJECTS = \ + $(am_operations_callback_wrapper_OBJECTS) +operations_callback_wrapper_LDADD = $(LDADD) +@SEPARATE_COMPILATION_TRUE@operations_callback_wrapper_DEPENDENCIES = \ +@SEPARATE_COMPILATION_TRUE@ libasio.a am_operations_composed_1_OBJECTS = operations/composed_1.$(OBJEXT) operations_composed_1_OBJECTS = $(am_operations_composed_1_OBJECTS) operations_composed_1_LDADD = $(LDADD) @@ -313,6 +331,13 @@ parallel_group_parallel_sort_OBJECTS = \ parallel_group_parallel_sort_LDADD = $(LDADD) @SEPARATE_COMPILATION_TRUE@parallel_group_parallel_sort_DEPENDENCIES = \ @SEPARATE_COMPILATION_TRUE@ libasio.a +am_parallel_group_ranged_wait_for_all_OBJECTS = \ + parallel_group/ranged_wait_for_all.$(OBJEXT) +parallel_group_ranged_wait_for_all_OBJECTS = \ + $(am_parallel_group_ranged_wait_for_all_OBJECTS) +parallel_group_ranged_wait_for_all_LDADD = $(LDADD) +@SEPARATE_COMPILATION_TRUE@parallel_group_ranged_wait_for_all_DEPENDENCIES = \ +@SEPARATE_COMPILATION_TRUE@ libasio.a am_parallel_group_wait_for_all_OBJECTS = \ parallel_group/wait_for_all.$(OBJEXT) parallel_group_wait_for_all_OBJECTS = \ @@ -378,6 +403,8 @@ am__depfiles_remade = ../../$(DEPDIR)/asio.Po \ executors/$(DEPDIR)/pipeline.Po \ executors/$(DEPDIR)/priority_scheduler.Po \ iostreams/$(DEPDIR)/http_client.Po \ + operations/$(DEPDIR)/c_callback_wrapper.Po \ + operations/$(DEPDIR)/callback_wrapper.Po \ operations/$(DEPDIR)/composed_1.Po \ operations/$(DEPDIR)/composed_2.Po \ operations/$(DEPDIR)/composed_3.Po \ @@ -387,6 +414,7 @@ am__depfiles_remade = ../../$(DEPDIR)/asio.Po \ operations/$(DEPDIR)/composed_7.Po \ operations/$(DEPDIR)/composed_8.Po \ parallel_group/$(DEPDIR)/parallel_sort.Po \ + parallel_group/$(DEPDIR)/ranged_wait_for_all.Po \ parallel_group/$(DEPDIR)/wait_for_all.Po \ parallel_group/$(DEPDIR)/wait_for_one.Po \ parallel_group/$(DEPDIR)/wait_for_one_error.Po \ @@ -422,6 +450,8 @@ SOURCES = $(libasio_a_SOURCES) $(deferred_deferred_1_SOURCES) \ $(executors_fork_join_SOURCES) $(executors_pipeline_SOURCES) \ $(executors_priority_scheduler_SOURCES) \ $(iostreams_http_client_SOURCES) \ + $(operations_c_callback_wrapper_SOURCES) \ + $(operations_callback_wrapper_SOURCES) \ $(operations_composed_1_SOURCES) \ $(operations_composed_2_SOURCES) \ $(operations_composed_3_SOURCES) \ @@ -431,6 +461,7 @@ SOURCES = $(libasio_a_SOURCES) $(deferred_deferred_1_SOURCES) \ $(operations_composed_7_SOURCES) \ $(operations_composed_8_SOURCES) \ $(parallel_group_parallel_sort_SOURCES) \ + $(parallel_group_ranged_wait_for_all_SOURCES) \ $(parallel_group_wait_for_all_SOURCES) \ $(parallel_group_wait_for_one_SOURCES) \ $(parallel_group_wait_for_one_error_SOURCES) \ @@ -453,6 +484,8 @@ DIST_SOURCES = $(am__libasio_a_SOURCES_DIST) \ $(executors_fork_join_SOURCES) $(executors_pipeline_SOURCES) \ $(executors_priority_scheduler_SOURCES) \ $(iostreams_http_client_SOURCES) \ + $(operations_c_callback_wrapper_SOURCES) \ + $(operations_callback_wrapper_SOURCES) \ $(operations_composed_1_SOURCES) \ $(operations_composed_2_SOURCES) \ $(operations_composed_3_SOURCES) \ @@ -462,6 +495,7 @@ DIST_SOURCES = $(am__libasio_a_SOURCES_DIST) \ $(operations_composed_7_SOURCES) \ $(operations_composed_8_SOURCES) \ $(parallel_group_parallel_sort_SOURCES) \ + $(parallel_group_ranged_wait_for_all_SOURCES) \ $(parallel_group_wait_for_all_SOURCES) \ $(parallel_group_wait_for_one_SOURCES) \ $(parallel_group_wait_for_one_error_SOURCES) \ @@ -488,8 +522,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ @@ -503,8 +535,9 @@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ -CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ @@ -513,9 +546,8 @@ DEPDIR = @DEPDIR@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ -EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ -GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -582,9 +614,11 @@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ +pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -621,6 +655,8 @@ executors_fork_join_SOURCES = executors/fork_join.cpp executors_pipeline_SOURCES = executors/pipeline.cpp executors_priority_scheduler_SOURCES = executors/priority_scheduler.cpp iostreams_http_client_SOURCES = iostreams/http_client.cpp +operations_c_callback_wrapper_SOURCES = operations/c_callback_wrapper.cpp +operations_callback_wrapper_SOURCES = operations/callback_wrapper.cpp operations_composed_1_SOURCES = operations/composed_1.cpp operations_composed_2_SOURCES = operations/composed_2.cpp operations_composed_3_SOURCES = operations/composed_3.cpp @@ -630,6 +666,7 @@ operations_composed_6_SOURCES = operations/composed_6.cpp operations_composed_7_SOURCES = operations/composed_7.cpp operations_composed_8_SOURCES = operations/composed_8.cpp parallel_group_parallel_sort_SOURCES = parallel_group/parallel_sort.cpp +parallel_group_ranged_wait_for_all_SOURCES = parallel_group/ranged_wait_for_all.cpp parallel_group_wait_for_all_SOURCES = parallel_group/wait_for_all.cpp parallel_group_wait_for_one_SOURCES = parallel_group/wait_for_one.cpp parallel_group_wait_for_one_error_SOURCES = parallel_group/wait_for_one_error.cpp @@ -853,6 +890,18 @@ operations/$(am__dirstamp): operations/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) operations/$(DEPDIR) @: > operations/$(DEPDIR)/$(am__dirstamp) +operations/c_callback_wrapper.$(OBJEXT): operations/$(am__dirstamp) \ + operations/$(DEPDIR)/$(am__dirstamp) + +operations/c_callback_wrapper$(EXEEXT): $(operations_c_callback_wrapper_OBJECTS) $(operations_c_callback_wrapper_DEPENDENCIES) $(EXTRA_operations_c_callback_wrapper_DEPENDENCIES) operations/$(am__dirstamp) + @rm -f operations/c_callback_wrapper$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(operations_c_callback_wrapper_OBJECTS) $(operations_c_callback_wrapper_LDADD) $(LIBS) +operations/callback_wrapper.$(OBJEXT): operations/$(am__dirstamp) \ + operations/$(DEPDIR)/$(am__dirstamp) + +operations/callback_wrapper$(EXEEXT): $(operations_callback_wrapper_OBJECTS) $(operations_callback_wrapper_DEPENDENCIES) $(EXTRA_operations_callback_wrapper_DEPENDENCIES) operations/$(am__dirstamp) + @rm -f operations/callback_wrapper$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(operations_callback_wrapper_OBJECTS) $(operations_callback_wrapper_LDADD) $(LIBS) operations/composed_1.$(OBJEXT): operations/$(am__dirstamp) \ operations/$(DEPDIR)/$(am__dirstamp) @@ -914,6 +963,13 @@ parallel_group/parallel_sort.$(OBJEXT): \ parallel_group/parallel_sort$(EXEEXT): $(parallel_group_parallel_sort_OBJECTS) $(parallel_group_parallel_sort_DEPENDENCIES) $(EXTRA_parallel_group_parallel_sort_DEPENDENCIES) parallel_group/$(am__dirstamp) @rm -f parallel_group/parallel_sort$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(parallel_group_parallel_sort_OBJECTS) $(parallel_group_parallel_sort_LDADD) $(LIBS) +parallel_group/ranged_wait_for_all.$(OBJEXT): \ + parallel_group/$(am__dirstamp) \ + parallel_group/$(DEPDIR)/$(am__dirstamp) + +parallel_group/ranged_wait_for_all$(EXEEXT): $(parallel_group_ranged_wait_for_all_OBJECTS) $(parallel_group_ranged_wait_for_all_DEPENDENCIES) $(EXTRA_parallel_group_ranged_wait_for_all_DEPENDENCIES) parallel_group/$(am__dirstamp) + @rm -f parallel_group/ranged_wait_for_all$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(parallel_group_ranged_wait_for_all_OBJECTS) $(parallel_group_ranged_wait_for_all_LDADD) $(LIBS) parallel_group/wait_for_all.$(OBJEXT): parallel_group/$(am__dirstamp) \ parallel_group/$(DEPDIR)/$(am__dirstamp) @@ -978,6 +1034,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@executors/$(DEPDIR)/pipeline.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@executors/$(DEPDIR)/priority_scheduler.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@iostreams/$(DEPDIR)/http_client.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/c_callback_wrapper.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/callback_wrapper.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/composed_1.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/composed_2.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/composed_3.Po@am__quote@ # am--include-marker @@ -987,6 +1045,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/composed_7.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@operations/$(DEPDIR)/composed_8.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@parallel_group/$(DEPDIR)/parallel_sort.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@parallel_group/$(DEPDIR)/ranged_wait_for_all.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@parallel_group/$(DEPDIR)/wait_for_all.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@parallel_group/$(DEPDIR)/wait_for_one.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@parallel_group/$(DEPDIR)/wait_for_one_error.Po@am__quote@ # am--include-marker @@ -1065,7 +1124,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -1178,6 +1236,8 @@ distclean: distclean-am -rm -f executors/$(DEPDIR)/pipeline.Po -rm -f executors/$(DEPDIR)/priority_scheduler.Po -rm -f iostreams/$(DEPDIR)/http_client.Po + -rm -f operations/$(DEPDIR)/c_callback_wrapper.Po + -rm -f operations/$(DEPDIR)/callback_wrapper.Po -rm -f operations/$(DEPDIR)/composed_1.Po -rm -f operations/$(DEPDIR)/composed_2.Po -rm -f operations/$(DEPDIR)/composed_3.Po @@ -1187,6 +1247,7 @@ distclean: distclean-am -rm -f operations/$(DEPDIR)/composed_7.Po -rm -f operations/$(DEPDIR)/composed_8.Po -rm -f parallel_group/$(DEPDIR)/parallel_sort.Po + -rm -f parallel_group/$(DEPDIR)/ranged_wait_for_all.Po -rm -f parallel_group/$(DEPDIR)/wait_for_all.Po -rm -f parallel_group/$(DEPDIR)/wait_for_one.Po -rm -f parallel_group/$(DEPDIR)/wait_for_one_error.Po @@ -1260,6 +1321,8 @@ maintainer-clean: maintainer-clean-am -rm -f executors/$(DEPDIR)/pipeline.Po -rm -f executors/$(DEPDIR)/priority_scheduler.Po -rm -f iostreams/$(DEPDIR)/http_client.Po + -rm -f operations/$(DEPDIR)/c_callback_wrapper.Po + -rm -f operations/$(DEPDIR)/callback_wrapper.Po -rm -f operations/$(DEPDIR)/composed_1.Po -rm -f operations/$(DEPDIR)/composed_2.Po -rm -f operations/$(DEPDIR)/composed_3.Po @@ -1269,6 +1332,7 @@ maintainer-clean: maintainer-clean-am -rm -f operations/$(DEPDIR)/composed_7.Po -rm -f operations/$(DEPDIR)/composed_8.Po -rm -f parallel_group/$(DEPDIR)/parallel_sort.Po + -rm -f parallel_group/$(DEPDIR)/ranged_wait_for_all.Po -rm -f parallel_group/$(DEPDIR)/wait_for_all.Po -rm -f parallel_group/$(DEPDIR)/wait_for_one.Po -rm -f parallel_group/$(DEPDIR)/wait_for_one_error.Po diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_1.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_1.cpp index 732fa4fa9b5..db9213eb3be 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_1.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_1.cpp @@ -2,17 +2,16 @@ // deferred_1.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::deferred; +using asio::deferred; int main() { diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_2.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_2.cpp index c33bbc2a5ed..07528282de5 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_2.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_2.cpp @@ -2,17 +2,16 @@ // deferred_2.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::deferred; +using asio::deferred; int main() { diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_3.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_3.cpp index 484dfca638f..396e40840a1 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_3.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_3.cpp @@ -2,17 +2,16 @@ // deferred_3.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::deferred; +using asio::deferred; template <typename CompletionToken> auto async_wait_twice(asio::steady_timer& timer, CompletionToken&& token) diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_4.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_4.cpp index 1f70821eaa5..a8ea73336d2 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_4.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_4.cpp @@ -2,17 +2,16 @@ // deferred_4.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::deferred; +using asio::deferred; template <typename CompletionToken> auto async_wait_twice(asio::steady_timer& timer, CompletionToken&& token) diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_5.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_5.cpp index b48056bd66d..d262b977811 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_5.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_5.cpp @@ -2,17 +2,16 @@ // deferred_5.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::deferred; +using asio::deferred; template <typename CompletionToken> auto async_wait_twice(asio::steady_timer& timer, CompletionToken&& token) diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_6.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_6.cpp index 502d43bc67c..7ccef58cc5c 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_6.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_6.cpp @@ -2,19 +2,17 @@ // deferred_6.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/append.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::append; -using asio::experimental::deferred; +using asio::append; +using asio::deferred; template <typename CompletionToken> auto async_wait_twice(asio::steady_timer& timer, CompletionToken&& token) diff --git a/3rdparty/asio/src/examples/cpp14/deferred/deferred_7.cpp b/3rdparty/asio/src/examples/cpp14/deferred/deferred_7.cpp index da49fc7040e..b0734542c79 100644 --- a/3rdparty/asio/src/examples/cpp14/deferred/deferred_7.cpp +++ b/3rdparty/asio/src/examples/cpp14/deferred/deferred_7.cpp @@ -2,19 +2,17 @@ // deferred_7.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/append.hpp> -#include <asio/experimental/deferred.hpp> #include <iostream> -using asio::experimental::append; -using asio::experimental::deferred; +using asio::append; +using asio::deferred; template <typename CompletionToken> auto async_wait_twice(asio::steady_timer& timer, CompletionToken&& token) diff --git a/3rdparty/asio/src/examples/cpp14/echo/async_tcp_echo_server.cpp b/3rdparty/asio/src/examples/cpp14/echo/async_tcp_echo_server.cpp index 49f17c2a3c1..9bd1b727500 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/async_tcp_echo_server.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/async_tcp_echo_server.cpp @@ -2,7 +2,7 @@ // async_tcp_echo_server.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/echo/async_udp_echo_server.cpp b/3rdparty/asio/src/examples/cpp14/echo/async_udp_echo_server.cpp index ea9a1da88a0..b059af95b82 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/async_udp_echo_server.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/async_udp_echo_server.cpp @@ -2,7 +2,7 @@ // async_udp_echo_server.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_client.cpp b/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_client.cpp index 96a843e41ad..8a281203f89 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_client.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_client.cpp @@ -2,7 +2,7 @@ // blocking_tcp_echo_client.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_server.cpp b/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_server.cpp index bcc5d4bb682..2116712616a 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_server.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/blocking_tcp_echo_server.cpp @@ -2,7 +2,7 @@ // blocking_tcp_echo_server.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_client.cpp b/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_client.cpp index 855f9e14e2a..4c8a2849d5b 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_client.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_client.cpp @@ -2,7 +2,7 @@ // blocking_udp_echo_client.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp b/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp index 816f6aeab6b..c3098bdb8fc 100644 --- a/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp +++ b/3rdparty/asio/src/examples/cpp14/echo/blocking_udp_echo_server.cpp @@ -2,7 +2,7 @@ // blocking_udp_echo_server.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/executors/async_1.cpp b/3rdparty/asio/src/examples/cpp14/executors/async_1.cpp index 2fb8ba56548..0d1bdfcb8bd 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/async_1.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/async_1.cpp @@ -20,16 +20,14 @@ void async_getline(IoExecutor io_ex, std::istream& is, Handler handler) execution::outstanding_work.tracked); // Post a function object to do the work asynchronously. - execution::execute( - asio::require(io_ex, execution::blocking.never), + asio::require(io_ex, execution::blocking.never).execute( [&is, work_ex, handler=std::move(handler)]() mutable { std::string line; std::getline(is, line); // Pass the result to the handler, via the associated executor. - execution::execute( - asio::prefer(work_ex, execution::blocking.possibly), + asio::prefer(work_ex, execution::blocking.possibly).execute( [line=std::move(line), handler=std::move(handler)]() mutable { handler(std::move(line)); diff --git a/3rdparty/asio/src/examples/cpp14/executors/async_2.cpp b/3rdparty/asio/src/examples/cpp14/executors/async_2.cpp index b8a28e68b87..ee4a72e80c3 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/async_2.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/async_2.cpp @@ -20,16 +20,14 @@ void async_getline(IoExecutor io_ex, std::istream& is, Handler handler) execution::outstanding_work.tracked); // Post a function object to do the work asynchronously. - execution::execute( - asio::require(io_ex, execution::blocking.never), + asio::require(io_ex, execution::blocking.never).execute( [&is, work_ex, handler=std::move(handler)]() mutable { std::string line; std::getline(is, line); // Pass the result to the handler, via the associated executor. - execution::execute( - asio::prefer(work_ex, execution::blocking.possibly), + asio::prefer(work_ex, execution::blocking.possibly).execute( [line=std::move(line), handler=std::move(handler)]() mutable { handler(std::move(line)); diff --git a/3rdparty/asio/src/examples/cpp14/executors/bank_account_1.cpp b/3rdparty/asio/src/examples/cpp14/executors/bank_account_1.cpp index abfd16a7ee0..a63d7fc059b 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/bank_account_1.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/bank_account_1.cpp @@ -16,8 +16,7 @@ class bank_account public: void deposit(int amount) { - execution::execute( - pool_.executor(), + pool_.executor().execute( [this, amount] { balance_ += amount; @@ -26,8 +25,7 @@ public: void withdraw(int amount) { - execution::execute( - pool_.executor(), + pool_.executor().execute( [this, amount] { if (balance_ >= amount) @@ -37,8 +35,7 @@ public: void print_balance() const { - execution::execute( - pool_.executor(), + pool_.executor().execute( [this] { std::cout << "balance = " << balance_ << "\n"; diff --git a/3rdparty/asio/src/examples/cpp14/executors/bank_account_2.cpp b/3rdparty/asio/src/examples/cpp14/executors/bank_account_2.cpp index 305d0ca5b86..c2de05156e8 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/bank_account_2.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/bank_account_2.cpp @@ -16,9 +16,7 @@ class bank_account public: void deposit(int amount) { - execution::execute( - asio::require(pool_.executor(), - execution::blocking.always), + asio::require(pool_.executor(), execution::blocking.always).execute( [this, amount] { balance_ += amount; @@ -27,9 +25,8 @@ public: void withdraw(int amount) { - execution::execute( - asio::require(pool_.executor(), - execution::blocking.always), + asio::require(pool_.executor(), + execution::blocking.always).execute( [this, amount] { if (balance_ >= amount) @@ -40,9 +37,7 @@ public: int balance() const { int result = 0; - execution::execute( - asio::require(pool_.executor(), - execution::blocking.always), + asio::require(pool_.executor(), execution::blocking.always).execute( [this, &result] { result = balance_; diff --git a/3rdparty/asio/src/examples/cpp14/executors/fork_join.cpp b/3rdparty/asio/src/examples/cpp14/executors/fork_join.cpp index a76437efad9..7e8a827356d 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/fork_join.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/fork_join.cpp @@ -32,8 +32,7 @@ public: // it is time to shut down, i.e. the use count is zero. for (thread_count_ = 0; thread_count_ < thread_count; ++thread_count_) { - execution::execute( - threads_.executor(), + threads_.executor().execute( [this] { std::unique_lock<std::mutex> lock(mutex_); @@ -252,8 +251,8 @@ void fork_join_sort(Iterator begin, Iterator end) { fork_executor fork(pool); join_guard join(fork); - execution::execute(fork, [=]{ fork_join_sort(begin, begin + n / 2); }); - execution::execute(fork, [=]{ fork_join_sort(begin + n / 2, end); }); + fork.execute([=]{ fork_join_sort(begin, begin + n / 2); }); + fork.execute([=]{ fork_join_sort(begin + n / 2, end); }); } std::inplace_merge(begin, begin + n / 2, end); } diff --git a/3rdparty/asio/src/examples/cpp14/executors/pipeline.cpp b/3rdparty/asio/src/examples/cpp14/executors/pipeline.cpp index 2d75e04fc0c..9754a27d425 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/pipeline.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/pipeline.cpp @@ -169,9 +169,7 @@ std::future<void> pipeline(queue_back<T> in, F f) f(in); }); std::future<void> fut = task.get_future(); - execution::execute( - asio::require(ex, execution::blocking.never), - std::move(task)); + asio::require(ex, execution::blocking.never).execute(std::move(task)); return fut; } @@ -191,8 +189,7 @@ std::future<void> pipeline(queue_back<T> in, F f, Tail... t) auto ex = get_associated_executor(f, thread_executor()); // Run the function. - execution::execute( - asio::require(ex, execution::blocking.never), + asio::require(ex, execution::blocking.never).execute( [in, out, f = std::move(f)]() mutable { f(in, out); @@ -219,8 +216,7 @@ std::future<void> pipeline(F f, Tail... t) auto ex = get_associated_executor(f, thread_executor()); // Run the function. - execution::execute( - asio::require(ex, execution::blocking.never), + asio::require(ex, execution::blocking.never).execute( [out, f = std::move(f)]() mutable { f(out); diff --git a/3rdparty/asio/src/examples/cpp14/executors/priority_scheduler.cpp b/3rdparty/asio/src/examples/cpp14/executors/priority_scheduler.cpp index da4caf0d0ef..20d36db933a 100644 --- a/3rdparty/asio/src/examples/cpp14/executors/priority_scheduler.cpp +++ b/3rdparty/asio/src/examples/cpp14/executors/priority_scheduler.cpp @@ -166,16 +166,16 @@ int main() auto med = asio::require(ex, custom_props::normal_priority); auto high = asio::require(ex, custom_props::high_priority); execution::any_executor<custom_props::priority> poly_high(high); - execution::execute(prefer_low, []{ std::cout << "1\n"; }); - execution::execute(low, []{ std::cout << "11\n"; }); - execution::execute(low, []{ std::cout << "111\n"; }); - execution::execute(med, []{ std::cout << "2\n"; }); - execution::execute(med, []{ std::cout << "22\n"; }); - execution::execute(high, []{ std::cout << "3\n"; }); - execution::execute(high, []{ std::cout << "33\n"; }); - execution::execute(high, []{ std::cout << "333\n"; }); - execution::execute(poly_high, []{ std::cout << "3333\n"; }); - execution::execute(asio::require(ex, custom_props::priority{-1}), [&]{ sched.stop(); }); + prefer_low.execute([]{ std::cout << "1\n"; }); + low.execute([]{ std::cout << "11\n"; }); + low.execute([]{ std::cout << "111\n"; }); + med.execute([]{ std::cout << "2\n"; }); + med.execute([]{ std::cout << "22\n"; }); + high.execute([]{ std::cout << "3\n"; }); + high.execute([]{ std::cout << "33\n"; }); + high.execute([]{ std::cout << "333\n"; }); + poly_high.execute([]{ std::cout << "3333\n"; }); + asio::require(ex, custom_props::priority{-1}).execute([&]{ sched.stop(); }); sched.run(); std::cout << "polymorphic query result = " << asio::query(poly_high, custom_props::priority{}) << "\n"; } diff --git a/3rdparty/asio/src/examples/cpp14/iostreams/http_client.cpp b/3rdparty/asio/src/examples/cpp14/iostreams/http_client.cpp index da64259bb50..3ae02e4f825 100644 --- a/3rdparty/asio/src/examples/cpp14/iostreams/http_client.cpp +++ b/3rdparty/asio/src/examples/cpp14/iostreams/http_client.cpp @@ -2,7 +2,7 @@ // http_client.cpp // ~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3rdparty/asio/src/examples/cpp14/operations/c_callback_wrapper.cpp b/3rdparty/asio/src/examples/cpp14/operations/c_callback_wrapper.cpp new file mode 100644 index 00000000000..33b1c26e8ae --- /dev/null +++ b/3rdparty/asio/src/examples/cpp14/operations/c_callback_wrapper.cpp @@ -0,0 +1,230 @@ +// +// c_callback_wrapper.cpp +// ~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include <asio.hpp> +#include <iostream> +#include <memory> +#include <new> + +//------------------------------------------------------------------------------ + +// This is a mock implementation of a C-based API that uses the function pointer +// plus void* context idiom for exposing a callback. + +void read_input(const char* prompt, void (*cb)(void*, const char*), void* arg) +{ + std::thread( + [prompt = std::string(prompt), cb, arg] + { + std::cout << prompt << ": "; + std::cout.flush(); + std::string line; + std::getline(std::cin, line); + cb(arg, line.c_str()); + }).detach(); +} + +//------------------------------------------------------------------------------ + +// This is an asynchronous operation that wraps the C-based API. + +// To map our completion handler into a function pointer / void* callback, we +// need to allocate some state that will live for the duration of the +// operation. A pointer to this state will be passed to the C-based API. +template <typename Handler> +class read_input_state +{ +public: + read_input_state(Handler&& handler) + : handler_(std::move(handler)), + work_(asio::make_work_guard(handler_)) + { + } + + // Create the state using the handler's associated allocator. + static read_input_state* create(Handler&& handler) + { + // A unique_ptr deleter that is used to destroy uninitialised objects. + struct deleter + { + // Get the handler's associated allocator type. If the handler does not + // specify an associated allocator, we will use a recycling allocator as + // the default. As the associated allocator is a proto-allocator, we must + // rebind it to the correct type before we can use it to allocate objects. + typename std::allocator_traits< + asio::associated_allocator_t<Handler, + asio::recycling_allocator<void>>>::template + rebind_alloc<read_input_state> alloc; + + void operator()(read_input_state* ptr) + { + std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1); + } + } d{asio::get_associated_allocator(handler, + asio::recycling_allocator<void>())}; + + // Allocate memory for the state. + std::unique_ptr<read_input_state, deleter> uninit_ptr( + std::allocator_traits<decltype(d.alloc)>::allocate(d.alloc, 1), d); + + // Construct the state into the newly allocated memory. This might throw. + read_input_state* ptr = + new (uninit_ptr.get()) read_input_state(std::move(handler)); + + // Release ownership of the memory and return the newly allocated state. + uninit_ptr.release(); + return ptr; + } + + static void callback(void* arg, const char* result) + { + read_input_state* self = static_cast<read_input_state*>(arg); + + // A unique_ptr deleter that is used to destroy initialised objects. + struct deleter + { + // Get the handler's associated allocator type. If the handler does not + // specify an associated allocator, we will use a recycling allocator as + // the default. As the associated allocator is a proto-allocator, we must + // rebind it to the correct type before we can use it to allocate objects. + typename std::allocator_traits< + asio::associated_allocator_t<Handler, + asio::recycling_allocator<void>>>::template + rebind_alloc<read_input_state> alloc; + + void operator()(read_input_state* ptr) + { + std::allocator_traits<decltype(alloc)>::destroy(alloc, ptr); + std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1); + } + } d{asio::get_associated_allocator(self->handler_, + asio::recycling_allocator<void>())}; + + // To conform to the rules regarding asynchronous operations and memory + // allocation, we must make a copy of the state and deallocate the memory + // before dispatching the completion handler. + std::unique_ptr<read_input_state, deleter> state_ptr(self, d); + read_input_state state(std::move(*self)); + state_ptr.reset(); + + // Dispatch the completion handler through the handler's associated + // executor, using the handler's associated allocator. + asio::dispatch(state.work_.get_executor(), + asio::bind_allocator(d.alloc, + [ + handler = std::move(state.handler_), + result = std::string(result) + ]() mutable + { + std::move(handler)(result); + })); + } + +private: + Handler handler_; + + // According to the rules for asynchronous operations, we need to track + // outstanding work against the handler's associated executor until the + // asynchronous operation is complete. + asio::executor_work_guard< + asio::associated_executor_t<Handler>> work_; +}; + +// The initiating function for the asynchronous operation. +template <typename CompletionToken> +auto async_read_input(const std::string& prompt, CompletionToken&& token) +{ + // Define a function object that contains the code to launch the asynchronous + // operation. This is passed the concrete completion handler, followed by any + // additional arguments that were passed through the call to async_initiate. + auto init = [](auto handler, const std::string& prompt) + { + // The body of the initiation function object creates the long-lived state + // and passes it to the C-based API, along with the function pointer. + using state_type = read_input_state<decltype(handler)>; + read_input(prompt.c_str(), &state_type::callback, + state_type::create(std::move(handler))); + }; + + // The async_initiate function is used to transform the supplied completion + // token to the completion handler. When calling this function we explicitly + // specify the completion signature of the operation. We must also return the + // result of the call since the completion token may produce a return value, + // such as a future. + return asio::async_initiate<CompletionToken, void(std::string)>( + init, // First, pass the function object that launches the operation, + token, // then the completion token that will be transformed to a handler, + prompt); // and, finally, any additional arguments to the function object. +} + +//------------------------------------------------------------------------------ + +void test_callback() +{ + asio::io_context io_context; + + // Test our asynchronous operation using a lambda as a callback. We will use + // an io_context to obtain an associated executor. + async_read_input("Enter your name", + asio::bind_executor(io_context, + [](const std::string& result) + { + std::cout << "Hello " << result << "\n"; + })); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + +void test_deferred() +{ + asio::io_context io_context; + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_read_input("Enter your name", asio::deferred); + + // Launch our asynchronous operation using a lambda as a callback. We will use + // an io_context to obtain an associated executor. + std::move(op)( + asio::bind_executor(io_context, + [](const std::string& result) + { + std::cout << "Hello " << result << "\n"; + })); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + +void test_future() +{ + // Test our asynchronous operation using the use_future completion token. + // This token causes the operation's initiating function to return a future, + // which may be used to synchronously wait for the result of the operation. + std::future<std::string> f = + async_read_input("Enter your name", asio::use_future); + + std::string result = f.get(); + std::cout << "Hello " << result << "\n"; +} + +//------------------------------------------------------------------------------ + +int main() +{ + test_callback(); + test_deferred(); + test_future(); +} diff --git a/3rdparty/asio/src/examples/cpp14/operations/callback_wrapper.cpp b/3rdparty/asio/src/examples/cpp14/operations/callback_wrapper.cpp new file mode 100644 index 00000000000..3d5774c7421 --- /dev/null +++ b/3rdparty/asio/src/examples/cpp14/operations/callback_wrapper.cpp @@ -0,0 +1,152 @@ +// +// callback_wrapper.cpp +// ~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include <asio.hpp> +#include <iostream> + +//------------------------------------------------------------------------------ + +// This is a mock implementation of an API that uses a move-only function object +// for exposing a callback. The callback has the signature void(std::string). + +template <typename Callback> +void read_input(const std::string& prompt, Callback cb) +{ + std::thread( + [prompt, cb = std::move(cb)]() mutable + { + std::cout << prompt << ": "; + std::cout.flush(); + std::string line; + std::getline(std::cin, line); + std::move(cb)(std::move(line)); + }).detach(); +} + +//------------------------------------------------------------------------------ + +// This is an asynchronous operation that wraps the callback-based API. + +// The initiating function for the asynchronous operation. +template <typename CompletionToken> +auto async_read_input(const std::string& prompt, CompletionToken&& token) +{ + // Define a function object that contains the code to launch the asynchronous + // operation. This is passed the concrete completion handler, followed by any + // additional arguments that were passed through the call to async_initiate. + auto init = [](auto handler, const std::string& prompt) + { + // According to the rules for asynchronous operations, we need to track + // outstanding work against the handler's associated executor until the + // asynchronous operation is complete. + auto work = asio::make_work_guard(handler); + + // Launch the operation with a callback that will receive the result and + // pass it through to the asynchronous operation's completion handler. + read_input(prompt, + [ + handler = std::move(handler), + work = std::move(work) + ](std::string result) mutable + { + // Get the handler's associated allocator. If the handler does not + // specify an allocator, use the recycling allocator as the default. + auto alloc = asio::get_associated_allocator( + handler, asio::recycling_allocator<void>()); + + // Dispatch the completion handler through the handler's associated + // executor, using the handler's associated allocator. + asio::dispatch(work.get_executor(), + asio::bind_allocator(alloc, + [ + handler = std::move(handler), + result = std::string(result) + ]() mutable + { + std::move(handler)(result); + })); + }); + }; + + // The async_initiate function is used to transform the supplied completion + // token to the completion handler. When calling this function we explicitly + // specify the completion signature of the operation. We must also return the + // result of the call since the completion token may produce a return value, + // such as a future. + return asio::async_initiate<CompletionToken, void(std::string)>( + init, // First, pass the function object that launches the operation, + token, // then the completion token that will be transformed to a handler, + prompt); // and, finally, any additional arguments to the function object. +} + +//------------------------------------------------------------------------------ + +void test_callback() +{ + asio::io_context io_context; + + // Test our asynchronous operation using a lambda as a callback. We will use + // an io_context to specify an associated executor. + async_read_input("Enter your name", + asio::bind_executor(io_context, + [](const std::string& result) + { + std::cout << "Hello " << result << "\n"; + })); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + +void test_deferred() +{ + asio::io_context io_context; + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_read_input("Enter your name", asio::deferred); + + // Launch our asynchronous operation using a lambda as a callback. We will use + // an io_context to obtain an associated executor. + std::move(op)( + asio::bind_executor(io_context, + [](const std::string& result) + { + std::cout << "Hello " << result << "\n"; + })); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + +void test_future() +{ + // Test our asynchronous operation using the use_future completion token. + // This token causes the operation's initiating function to return a future, + // which may be used to synchronously wait for the result of the operation. + std::future<std::string> f = + async_read_input("Enter your name", asio::use_future); + + std::string result = f.get(); + std::cout << "Hello " << result << "\n"; +} + +//------------------------------------------------------------------------------ + +int main() +{ + test_callback(); + test_deferred(); + test_future(); +} diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_1.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_1.cpp index 05b1479f2ff..80eaceddf71 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_1.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_1.cpp @@ -2,12 +2,13 @@ // composed_1.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/use_future.hpp> @@ -31,14 +32,21 @@ template <typename CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is void. However, - // when the completion token is asio::yield_context (used for stackful - // coroutines) the return type would be std::size_t, and when the completion - // token is asio::use_future it would be std::future<std::size_t>. + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is void. + // However, when the completion token is asio::yield_context (used for + // stackful coroutines) the return type would be std::size_t, and when the + // completion token is asio::use_future it would be std::future<std::size_t>. + // When the completion token is asio::deferred, the return type differs for + // each asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from - // the return type of our underlying asynchronous operation + // the return type of our underlying asynchronous operation. { // When delegating to the underlying operation we must take care to perfectly // forward the completion token. This ensures that our operation works @@ -77,6 +85,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_message(socket, + "Testing deferred\r\n", asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error, std::size_t n) + { + if (!error) + { + std::cout << n << " bytes transferred\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -109,5 +150,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_2.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_2.cpp index 15422454c40..18086bd0627 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_2.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_2.cpp @@ -2,12 +2,13 @@ // composed_2.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/use_future.hpp> @@ -20,6 +21,10 @@ using asio::ip::tcp; +// NOTE: This example requires the new asio::async_initiate function. For +// an example that works with the Networking TS style of completion tokens, +// please see an older version of asio. + //------------------------------------------------------------------------------ // This next simplest example of a composed asynchronous operation involves @@ -33,38 +38,87 @@ auto async_write_message(tcp::socket& socket, const char* message, bool allow_partial_write, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is void. However, - // when the completion token is asio::yield_context (used for stackful - // coroutines) the return type would be std::size_t, and when the completion - // token is asio::use_future it would be std::future<std::size_t>. + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is void. + // However, when the completion token is asio::yield_context (used for + // stackful coroutines) the return type would be std::size_t, and when the + // completion token is asio::use_future it would be std::future<std::size_t>. + // When the completion token is asio::deferred, the return type differs for + // each asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from - // the return type of our underlying asynchronous operation + // the return type of asio::async_initiate. { - // As the return type of the initiating function is deduced solely from the - // CompletionToken and completion signature, we know that two different - // asynchronous operations having the same completion signature will produce - // the same return type, when passed the same CompletionToken. This allows us - // to trivially delegate to alternate implementations. - if (allow_partial_write) - { - // When delegating to an underlying operation we must take care to - // perfectly forward the completion token. This ensures that our operation - // works correctly with move-only function objects as callbacks, as well as - // other completion token types. - return socket.async_write_some( - asio::buffer(message, std::strlen(message)), - std::forward<CompletionToken>(token)); - } - else + // In addition to determining the mechanism by which an asynchronous + // operation delivers its result, a completion token also determines the time + // when the operation commences. For example, when the completion token is a + // simple callback the operation commences before the initiating function + // returns. However, if the completion token's delivery mechanism uses a + // future, we might instead want to defer initiation of the operation until + // the returned future object is waited upon. + // + // To enable this, when implementing an asynchronous operation we must + // package the initiation step as a function object. The initiation function + // object's call operator is passed the concrete completion handler produced + // by the completion token. This completion handler matches the asynchronous + // operation's completion handler signature, which in this example is: + // + // void(std::error_code error, std::size_t) + // + // The initiation function object also receives any additional arguments + // required to start the operation. (Note: We could have instead passed these + // arguments in the lambda capture set. However, we should prefer to + // propagate them as function call arguments as this allows the completion + // token to optimise how they are passed. For example, a lazy future which + // defers initiation would need to make a decay-copy of the arguments, but + // when using a simple callback the arguments can be trivially forwarded + // straight through.) + auto initiation = [](auto&& completion_handler, tcp::socket& socket, + const char* message, bool allow_partial_write) { - // As above, we must perfectly forward the completion token when calling - // the alternate underlying operation. - return asio::async_write(socket, - asio::buffer(message, std::strlen(message)), - std::forward<CompletionToken>(token)); - } + if (allow_partial_write) + { + // When delegating to an underlying operation we must take care to + // perfectly forward the completion handler. This ensures that our + // operation works correctly with move-only function objects as + // callbacks. + return socket.async_write_some( + asio::buffer(message, std::strlen(message)), + std::forward<decltype(completion_handler)>(completion_handler)); + } + else + { + // As above, we must perfectly forward the completion handler when calling + // the alternate underlying operation. + return asio::async_write(socket, + asio::buffer(message, std::strlen(message)), + std::forward<decltype(completion_handler)>(completion_handler)); + } + }; + + // The asio::async_initiate function takes: + // + // - our initiation function object, + // - the completion token, + // - the completion handler signature, and + // - any additional arguments we need to initiate the operation. + // + // It then asks the completion token to create a completion handler (i.e. a + // callback) with the specified signature, and invoke the initiation function + // object with this completion handler as well as the additional arguments. + // The return value of async_initiate is the result of our operation's + // initiating function. + // + // Note that we wrap non-const reference arguments in std::reference_wrapper + // to prevent incorrect decay-copies of these objects. + return asio::async_initiate< + CompletionToken, void(std::error_code, std::size_t)>( + initiation, token, std::ref(socket), message, allow_partial_write); } //------------------------------------------------------------------------------ @@ -95,6 +149,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_message(socket, + "Testing deferred\r\n", false, asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error, std::size_t n) + { + if (!error) + { + std::cout << n << " bytes transferred\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -127,5 +214,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_3.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_3.cpp index 0ac277f1e34..7b347944768 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_3.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_3.cpp @@ -2,13 +2,14 @@ // composed_3.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio/bind_executor.hpp> +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/use_future.hpp> @@ -37,12 +38,19 @@ template <typename CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from // the return type of asio::async_initiate. @@ -149,6 +157,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_message(socket, + "Testing deferred\r\n", asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Message sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -182,5 +223,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_4.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_4.cpp index 879e38ca0db..808a179e2d3 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_4.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_4.cpp @@ -2,13 +2,14 @@ // composed_4.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio/bind_executor.hpp> +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/use_future.hpp> @@ -38,12 +39,19 @@ template <typename CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from // the return type of asio::async_initiate. @@ -165,6 +173,38 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_message(socket, "", asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Message sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -197,5 +237,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_5.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_5.cpp index 560773217f6..c28cc8af129 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_5.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_5.cpp @@ -2,12 +2,13 @@ // composed_5.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/use_future.hpp> @@ -37,12 +38,19 @@ template <typename T, typename CompletionToken> auto async_write_message(tcp::socket& socket, const T& message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from // the return type of asio::async_initiate. @@ -202,6 +210,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_message(socket, + std::string("abcdef"), asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Message sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -234,5 +275,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_6.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_6.cpp index d0304de6a99..82c0cd72237 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_6.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_6.cpp @@ -2,12 +2,13 @@ // composed_6.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include <asio/deferred.hpp> #include <asio/executor_work_guard.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> @@ -42,12 +43,19 @@ auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from // the return type of asio::async_initiate. @@ -108,9 +116,7 @@ auto async_write_messages(tcp::socket& socket, // As our composed operation performs multiple underlying I/O operations, // we should maintain a work object against the I/O executor. This tells // the I/O executor that there is still more work to come in the future. - typename std::decay<decltype(asio::prefer( - std::declval<tcp::socket::executor_type>(), - asio::execution::outstanding_work.tracked))>::type io_work_; + asio::executor_work_guard<tcp::socket::executor_type> io_work_; // The user-supplied completion handler, called once only on completion // of the entire composed operation. @@ -147,6 +153,9 @@ auto async_write_messages(tcp::socket& socket, // This point is reached only on completion of the entire composed // operation. + // We no longer have any future work coming for the I/O executor. + io_work_.reset(); + // Deallocate the encoded message before calling the user-supplied // completion handler. encoded_message_.reset(); @@ -197,8 +206,7 @@ auto async_write_messages(tcp::socket& socket, socket, std::move(encoded_message), repeat_count, std::move(delay_timer), intermediate_completion_handler::starting, - asio::prefer(socket.get_executor(), - asio::execution::outstanding_work.tracked), + asio::make_work_guard(socket.get_executor()), std::forward<decltype(completion_handler)>(completion_handler)}); }; @@ -262,6 +270,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_messages(socket, + "Testing deferred\r\n", 5, asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Messages sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -294,5 +335,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_7.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_7.cpp index 0158292e9d9..841249bef5b 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_7.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_7.cpp @@ -2,13 +2,14 @@ // composed_7.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio/compose.hpp> +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/steady_timer.hpp> @@ -42,15 +43,22 @@ auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from - // the return type of asio::async_initiate. + // the return type of asio::async_compose. { // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the composed asynchronous operation. @@ -183,6 +191,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_messages(socket, + "Testing deferred\r\n", 5, asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Messages sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -215,5 +256,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/operations/composed_8.cpp b/3rdparty/asio/src/examples/cpp14/operations/composed_8.cpp index a22a500b67e..d1f46ddce54 100644 --- a/3rdparty/asio/src/examples/cpp14/operations/composed_8.cpp +++ b/3rdparty/asio/src/examples/cpp14/operations/composed_8.cpp @@ -2,7 +2,7 @@ // composed_8.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -10,6 +10,7 @@ #include <asio/compose.hpp> #include <asio/coroutine.hpp> +#include <asio/deferred.hpp> #include <asio/io_context.hpp> #include <asio/ip/tcp.hpp> #include <asio/steady_timer.hpp> @@ -46,15 +47,22 @@ auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination - // of CompletionToken type and the completion handler's signature. When the - // completion token is a simple callback, the return type is always void. - // In this example, when the completion token is asio::yield_context - // (used for stackful coroutines) the return type would be also be void, as + // of: + // + // - the CompletionToken type, + // - the completion handler signature, and + // - the asynchronous operation's initiation function object. + // + // When the completion token is a simple callback, the return type is always + // void. In this example, when the completion token is asio::yield_context + // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the - // completion token is asio::use_future it would be std::future<void>. + // completion token is asio::use_future it would be std::future<void>. When + // the completion token is asio::deferred, the return type differs for each + // asynchronous operation. // // In C++14 we can omit the return type as it is automatically deduced from - // the return type of asio::async_initiate. + // the return type of asio::async_compose. { // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the composed asynchronous operation. @@ -176,6 +184,39 @@ void test_callback() //------------------------------------------------------------------------------ +void test_deferred() +{ + asio::io_context io_context; + + tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); + tcp::socket socket = acceptor.accept(); + + // Test our asynchronous operation using the deferred completion token. This + // token causes the operation's initiating function to package up the + // operation with its arguments to return a function object, which may then be + // used to launch the asynchronous operation. + auto op = async_write_messages(socket, + "Testing deferred\r\n", 5, asio::deferred); + + // Launch the operation using a lambda as a callback. + std::move(op)( + [](const std::error_code& error) + { + if (!error) + { + std::cout << "Messages sent\n"; + } + else + { + std::cout << "Error: " << error.message() << "\n"; + } + }); + + io_context.run(); +} + +//------------------------------------------------------------------------------ + void test_future() { asio::io_context io_context; @@ -208,5 +249,6 @@ void test_future() int main() { test_callback(); + test_deferred(); test_future(); } diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/parallel_sort.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/parallel_sort.cpp index 4df92a0467d..8bb7cdfd719 100644 --- a/3rdparty/asio/src/examples/cpp14/parallel_group/parallel_sort.cpp +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/parallel_sort.cpp @@ -2,14 +2,13 @@ // parallel_sort.cpp // ~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <asio.hpp> -#include <asio/experimental/append.hpp> #include <asio/experimental/parallel_group.hpp> #include <algorithm> #include <chrono> @@ -89,7 +88,7 @@ auto parallel_sort( [self = std::make_shared<self_type>(std::move(self))] { asio::dispatch( - asio::experimental::append( + asio::append( std::move(*self), 0)); } ); diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/ranged_wait_for_all.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/ranged_wait_for_all.cpp new file mode 100644 index 00000000000..18772884072 --- /dev/null +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/ranged_wait_for_all.cpp @@ -0,0 +1,70 @@ +// +// ranged_wait_for_all.cpp +// ~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include <asio.hpp> +#include <asio/experimental/parallel_group.hpp> +#include <iostream> +#include <vector> + +#ifdef ASIO_HAS_POSIX_STREAM_DESCRIPTOR + +int main() +{ + asio::io_context ctx; + + asio::posix::stream_descriptor out(ctx, ::dup(STDOUT_FILENO)); + asio::posix::stream_descriptor err(ctx, ::dup(STDERR_FILENO)); + + using op_type = decltype( + out.async_write_some( + asio::buffer("", 0), + asio::deferred + ) + ); + + std::vector<op_type> ops; + + ops.push_back( + out.async_write_some( + asio::buffer("first\r\n", 7), + asio::deferred + ) + ); + + ops.push_back( + err.async_write_some( + asio::buffer("second\r\n", 8), + asio::deferred + ) + ); + + asio::experimental::make_parallel_group(ops).async_wait( + asio::experimental::wait_for_all(), + []( + std::vector<std::size_t> completion_order, + std::vector<std::error_code> ec, + std::vector<std::size_t> n + ) + { + for (std::size_t i = 0; i < completion_order.size(); ++i) + { + std::size_t idx = completion_order[i]; + std::cout << "operation " << idx << " finished: "; + std::cout << ec[idx] << ", " << n[idx] << "\n"; + } + } + ); + + ctx.run(); +} + +#else // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) +int main() {} +#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_all.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_all.cpp index b216c37d7cc..f007326326b 100644 --- a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_all.cpp +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_all.cpp @@ -2,7 +2,7 @@ // wait_for_all.cpp // ~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -12,6 +12,8 @@ #include <asio/experimental/parallel_group.hpp> #include <iostream> +#ifdef ASIO_HAS_POSIX_STREAM_DESCRIPTOR + int main() { asio::io_context ctx; @@ -56,3 +58,7 @@ int main() ctx.run(); } + +#else // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) +int main() {} +#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one.cpp index aa83f4922c3..7b25e26d678 100644 --- a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one.cpp +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one.cpp @@ -2,7 +2,7 @@ // wait_for_one.cpp // ~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -12,6 +12,8 @@ #include <asio/experimental/parallel_group.hpp> #include <iostream> +#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) + int main() { asio::io_context ctx; @@ -56,3 +58,7 @@ int main() ctx.run(); } + +#else // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) +int main() {} +#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_error.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_error.cpp index 584c5c3fc00..c157d0b3355 100644 --- a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_error.cpp +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_error.cpp @@ -2,7 +2,7 @@ // wait_for_one_error.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -12,6 +12,8 @@ #include <asio/experimental/parallel_group.hpp> #include <iostream> +#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) + int main() { asio::io_context ctx; @@ -56,3 +58,7 @@ int main() ctx.run(); } + +#else // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) +int main() {} +#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) diff --git a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_success.cpp b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_success.cpp index 45700024423..a328600a9fc 100644 --- a/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_success.cpp +++ b/3rdparty/asio/src/examples/cpp14/parallel_group/wait_for_one_success.cpp @@ -2,7 +2,7 @@ // wait_for_one_error.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -12,6 +12,8 @@ #include <asio/experimental/parallel_group.hpp> #include <iostream> +#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) + int main() { asio::io_context ctx; @@ -56,3 +58,7 @@ int main() ctx.run(); } + +#else // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) +int main() {} +#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) |