From 113367b2005aee967a3edcd56b6f958fa6eff365 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Fri, 31 Aug 2018 18:28:01 -0700 Subject: [PATCH 01/16] Doc updated. --- README.md | 4 ++-- doc/faq.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27255236..c3b04db4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Release notes and upcoming development plans are [available here](doc/release.md # Overview -For many developers, asynchronous network programming in C++ is not easy. It is complex, has many pitfalls, and requires designing C++ code in a way that is not natural for many developers, even those with years of experience. Chops Net IP ("C"onnective "H"andcrafted "Op"enwork "S"oftware, Networking over Internet Protocol) simplifies asynchronous network programming and provides useful (and tasty!) abstractions for many types of communication patterns. +For many software developers, asynchronous network programming in C++ is not easy. It is complex, has many pitfalls, and requires designing C++ code in a way that is not natural, even for those with years of experience. Chops Net IP ("C"onnective "H"andcrafted "Op"enwork "S"oftware, Networking over Internet Protocol) simplifies asynchronous network programming and provides useful (and tasty!) abstractions for many types of communication patterns. Chops Net IP is layered on top of the C++ Networking Technical Standard (TS). This allows it to be portable across many compilers and platforms and when the C++ Networking TS is standardized (C++ 20? We all hope!) Chops Net IP will directly use the networking facilities of the C++ standard library. @@ -63,7 +63,7 @@ A detailed overview, a C++ socket library comparison, and a FAQ is [available he # C++ Language Requirements and Alternatives -C++ 17 is the primary baseline for this repository. +C++ 17 is the primary standards baseline for this repository. There is also one future C++ facility in use (`std::expected`, for better and simpler error handling). A significant number of C++ 11 features are in the implementation and API. There are also limited C++ 14 and 17 features in use, although they tend to be relatively simple features of those standards (e.g. `std::byte`, structured bindings). For users that don't want to use the latest C++ compilers or compile with C++ 17 flags, Martin Moene provides an excellent set of header-only libraries that implement many useful C++ library features, both C++ 17 as well as future C++ standards (see [References](doc/references.md)). diff --git a/doc/faq.md b/doc/faq.md index ba98b443..5e22f770 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -8,6 +8,8 @@ - This is an indication that the remote end is not processing data fast enough (or that data is being produced too fast). The application can query outgoing queue stats to determine if this scenario is occurring. - Why not provide a configuration API for a table-driven network application? - There are many different formats and types of configurations, including dynamically generated configurations. Configuration should be a separate concern from the Chops Net IP library. Configuration parsing for common formats (e.g. JSON) may be added to the `component` directory (non-dependent convenience classes and functions) in the future. +- Are there logging or tracing facilities in Chops Net IP? + - No. There is not a logging library or design that is generic enough to work in every environment. Even general purpose logging libraries have a set of tradeoffs that are not acceptable for Chops Net IP. Instead, the approach taken by Chops Net IP is to provide customization points for every meaningful step in the networking processing flow. This allows the application complete flexibility in using whatever logging facilities it wishes. - Is Chops Net IP a complete wrapper over the C++ Networking TS? - No. There are access points that expose various Networking TS facilities, and Networking TS `endpoints` are used in the Chops Net IP API. In particular, Chops Net IP provides an interface to access the underlying Networking TS socket and the application can directly set (or query) socket options (versus wrapping and exactly duplicating the functionality). - What are some of the subtle design challenges in the implementation? From c2322059f82b55299a904bd47fb297dca3685ec3 Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Fri, 28 Sep 2018 13:09:10 -0700 Subject: [PATCH 02/16] Documentation updates. --- doc/about.md | 4 ++-- doc/faq.md | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/about.md b/doc/about.md index 71913dfa..20de1359 100644 --- a/doc/about.md +++ b/doc/about.md @@ -1,8 +1,8 @@ # Author Notes and Contributor Information -The primary author of Chops Net IP is Cliff Green, softwarelibre at codewrangler dot net. Cliff is a software engineer and has worked for many years writing infrastructure libraries and applications for use in networked and distributed systems, typically where high reliability or uptime is required. The domains where he has worked include wireless networks, location technology, and large scale embedded and simulation systems in the military aerospace industry. He has volunteered every year at CppCon and presented at BoostCon (before it was renamed to C++ Now). +The primary author of Chops Net IP is Cliff Green, softwarelibre at codewrangler dot net. Cliff is a software engineer, working for many years writing infrastructure libraries and applications for use in networked and distributed systems, typically where high reliability or uptime is required. The domains where he has worked include wireless networks (cellphone, pager), location technology, and large scale embedded and simulation systems in the military aerospace industry. He has volunteered every year at CppCon and presented at BoostCon (before it was renamed to C++ Now). -Cliff lives in the Seattle area and you may know him from other interests including volleyball, hiking, railroading (both the model variety and the real life big ones), music, or even parent support activities (if you are having major difficulties with your teen check out the Changes Parent Support Network, http://cpsn.org). +Cliff lives in the Seattle area and you may know him from other interests including volleyball, hiking, railroading (both the model variety and the real life big ones), music, or even parent support activities (if you are having major difficulties with your teen, check out the Changes Parent Support Network, http://cpsn.org). (Fill in info on co-authors and contributors.) diff --git a/doc/faq.md b/doc/faq.md index 5e22f770..47555f09 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -1,5 +1,11 @@ # Chops Net IP FAQ +- Why should I use Chops Net IP? + - If you need general IP (Internet Protocol) networking in your application it will make your development job easier. +- Why not use one of the many other networking or socket libraries? + - Chops Net IP scales very well, using system resources efficiently. It performs well. It is portable across many compilers and platforms. It defines application customization points that few other libraries have. The abstractions it provides are flexible and useful in many domains. It provides TCP, UDP, and UDP multicasting functionality, abstracting away many of the differences between those protocols. +- When should I not use Chops Net IP? + - When you need abstractions for a specific complex and widely used domain. For example, serious web server applications should consider using Boost Beast (written by Vinnie Falco) or one of the many web frameworks that are available. If absolute raw performance is needed, writing directly to the C++ Networking TS (or using a similar library) would be better, giving up the convenience and flexibility that Chops Net IP provides. - Is Chops Net IP a framework? - No. It is a general purpose library. There are no specific network protocols required by the library and no wire protocols added by the library. It can communicate with any TCP or UDP application. Obviously the wire protocols and communication semantics need to be appropriately implemented by the application using the Chops Net IP library. - Wny is a queue required for outgoing data? @@ -7,7 +13,7 @@ - What if the outgoing data queue becomes large? - This is an indication that the remote end is not processing data fast enough (or that data is being produced too fast). The application can query outgoing queue stats to determine if this scenario is occurring. - Why not provide a configuration API for a table-driven network application? - - There are many different formats and types of configurations, including dynamically generated configurations. Configuration should be a separate concern from the Chops Net IP library. Configuration parsing for common formats (e.g. JSON) may be added to the `component` directory (non-dependent convenience classes and functions) in the future. + - There are many different formats and types of configurations, including dynamically generated configurations. Configuration should be a separate concern from the Chops Net IP library. Configuration parsing for common formats (e.g. JSON) may be added to the `component` directory (non-dependent convenience classes and functions) in the future or provided in separate repositories. - Are there logging or tracing facilities in Chops Net IP? - No. There is not a logging library or design that is generic enough to work in every environment. Even general purpose logging libraries have a set of tradeoffs that are not acceptable for Chops Net IP. Instead, the approach taken by Chops Net IP is to provide customization points for every meaningful step in the networking processing flow. This allows the application complete flexibility in using whatever logging facilities it wishes. - Is Chops Net IP a complete wrapper over the C++ Networking TS? From 1e6eab2df85952ee1190868a0ae57084210e053e Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Mon, 11 Mar 2019 11:36:34 -0700 Subject: [PATCH 03/16] Doc updates after importing repository. --- README.md | 14 ++++++-------- doc/lib_comparison.md | 2 +- doc/overview.md | 4 ++-- doc/release.md | 1 - 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c3b04db4..14f223e9 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Chops Net IP - Connective Handcrafted Openwork Software for Asynchronous IP Networking -Chops Net IP is a C++ library that makes asynchronous networking programming fun. Or at least if not fun, it makes network programming easier and safer without significantly sacrificing performance. It is built on top of the C++ Networking Technical Standard (TS) and handles Internet Protocol (IP) communications (TCP, UDP, UDP multicast). It is written using modern C++ design idioms and the latest (2017) C++ standard. +Chops Net IP is a C++ library that makes asynchronous networking programming fun. Or at least if not fun, it makes network programming easier and safer without significantly sacrificing performance. It is built on top of the Asio asynchronous networking library and handles Internet Protocol (IP) communications including TCP, UDP, and UDP multicast. It is written using modern C++ design idioms and the latest (2017) C++ standard. This project is distributed under the [Boost Software License](LICENSE.txt). ## Chops Net IP Release Status -Release 1.0 is under development as of August 2018, awaiting `std::expected` (proposed for C++ 20) error handling improvement, CMake config file completion, and additional testing under multiple compilers and platforms. +Release 1.0 is under development as of March 2019, awaiting `std::expected` (proposed for C++ 20) error handling improvement, CMake config file completion, and additional testing under multiple compilers and platforms. Release notes and upcoming development plans are [available here](doc/release.md). @@ -14,7 +14,7 @@ Release notes and upcoming development plans are [available here](doc/release.md For many software developers, asynchronous network programming in C++ is not easy. It is complex, has many pitfalls, and requires designing C++ code in a way that is not natural, even for those with years of experience. Chops Net IP ("C"onnective "H"andcrafted "Op"enwork "S"oftware, Networking over Internet Protocol) simplifies asynchronous network programming and provides useful (and tasty!) abstractions for many types of communication patterns. -Chops Net IP is layered on top of the C++ Networking Technical Standard (TS). This allows it to be portable across many compilers and platforms and when the C++ Networking TS is standardized (C++ 20? We all hope!) Chops Net IP will directly use the networking facilities of the C++ standard library. +Chops Net IP is layered on top of Chris Kohlhoff's Asio library (see [References](doc/references.md)) allowing it to be portable across many compilers and platforms. When the C++ Networking TS is standardized (possibly C++ 23 but more likely C++ 26) Chops Net IP will directly use the networking facilities of the C++ standard library. Chops Net IP simplifies application code that processes data on multiple simultaneous TCP connections or UDP endpoints. All Chops Net IP operations (from the application viewpoint) are no-wait (i.e. there are no blocking methods) and all network processing operations are performed asynchronously. @@ -75,8 +75,8 @@ The libraries and API's have minimal (as possible) library dependencies (there a Production external dependencies: -- Version 1.11 (or later) of Chris Kohlhoff's `networking-ts-impl` (Networking TS) repository is required for some components. Note that the version number is from the Asio version and may not exactly match the Networking TS version. -- Version 0.9 (or later) of `utility-rack`, which is a repository in the same account as Chops Net IP (`shared_buffer.hpp` and `erase_where.hpp` are required). +- Version 1.12 (or later) of Chris Kohlhoff's `asio` repository is required. Note that it is the stand-alone library, not the Boost Asio implementation. +- Version 0.9 (or later) of `utility-rack`, which is a repository in the same GitHub account as Chops Net IP (`shared_buffer.hpp` and `erase_where.hpp` are required). - Version 0.1 (or later) of Martin Moene's `expected-lite` library. Test external dependencies: @@ -103,9 +103,7 @@ See [References](doc/references.md) for details on dependencies and inspirations # About -The primary author of Chops is Cliff Green, softwarelibre at codewrangler dot net. - -Co-authors include ... +The primary author of Chops is Cliff Green, cliffg at connectivecpp dot com. The primary co-author is Thurman Gillespy, thurmang at connectivecpp dot com. Contributors include ... diff --git a/doc/lib_comparison.md b/doc/lib_comparison.md index cb164b98..7415c057 100644 --- a/doc/lib_comparison.md +++ b/doc/lib_comparison.md @@ -17,7 +17,7 @@ The secondary criteria includes: ## Asio and C++ Networking TS -Both Asio and the C++ Networking TS provide the foundation and underlying asynchronous model for Chops Net IP. Chops Net IP is layered on top of the C++ Networking TS and could easily be ported to use Asio. Chops Net IP provides usage and abstraction advantages as outlined in the overview documentation. +Asio provides the foundation and underlying asynchronous model for Chops Net IP. The C++ Networking TS is still in development, awaiting standardization and modularization of core components such as executors. Chops Net IP provides usage and abstraction advantages as outlined in the overview documentation. ## ACE diff --git a/doc/overview.md b/doc/overview.md index f6b63413..b65cc712 100644 --- a/doc/overview.md +++ b/doc/overview.md @@ -52,7 +52,7 @@ Chops Net IP states and transitions match existing standard network protocol beh Even though an implicit state transition table exists within the Chops Net IP library (matching network protocol behavior), there are not any explicit state flags or methods to query the state through the API. Instead, state transitions are handled through application supplied function object callbacks, which notify the application that something interesting has happened and containing objects for further interaction and processing. In other words, there is not an "is_connected" method with the Chops Net IP library. Instead, an application can layer its own state on top of Chops Net IP (if desired), using the function object callbacks to manage the state. -Pro tip - Chops Net IP follows the implicit state model of the Networking TS and Asio (and similar) libraries where state transitions are implemented through chaining function objects on asynchronous operations. Developers familiar with implicit or explicit state transition models will be familiar with the application model defined for Chops Net IP. Chops Net IP insulates the application from the intricacies of the Networking TS API and simplifies the state transition details. +Pro tip - Chops Net IP follows the implicit state model of the Asio library (and similar libraries) where state transitions are implemented through chaining function objects on asynchronous operations. Developers familiar with implicit or explicit state transition models will be familiar with the application model defined for Chops Net IP. Chops Net IP insulates the application from the intricacies of the Asio library and simplifies the state transition details. ![Image of Chops Net IP objects and states](object_states_diagram.png) @@ -134,7 +134,7 @@ Where to provide the customization points in the API is one of the most crucial Since data can be sent at any time and at any rate by the application, a sending queue is required. The queue can be queried to find out if congestion is occurring. -Mutex locking is kept to a minimum in the library. Alternatively, some of the internal handler classes take incoming parameters and post the data through the `io context`. This allows multiple threads to be calling into one internal handler and as long as the parameter data is thread-safe (which it is), thread safety is managed by the Networking TS executor and posting queue code. +Mutex locking is kept to a minimum in the library. Alternatively, some of the internal handler classes take incoming parameters and post the data through the `io context`. This allows multiple threads to be calling into one internal handler and as long as the parameter data is thread-safe (which it is), thread safety is managed by the Asio executor and posting queue code. In the areas where data is potentially accessed concurrently, it is typically protected by `std::atomic` wraps. For example, outgoing queue statistics and `is_started` flags are all `std::atomic`. While this guarantees runtime integrity (i.e. no crashes), it does mean that statistics might have temporary inconsistency with each other. For example, an outgoing buffer might be popped from the queue exactly between an application querying and accessing two outgoing counters. This potential inconsistency is not considered to be an issue, since the queue counters are only meant for general congestion queries, not exact statistical gathering. diff --git a/doc/release.md b/doc/release.md index 19ed0b3e..16b6e58e 100644 --- a/doc/release.md +++ b/doc/release.md @@ -28,7 +28,6 @@ All tests run, although they are still limited (see next steps and constraints). ### Next Steps, ToDo's, Problems, and Constraints: -- This is a good point to ask for project help and collaboration, which will be greatly appreciated (for many reasons). - The code is well doxygenated, and there is a good start on the high level descriptions, but tutorials and other high-level documentation is needed. A "doxygen to markdown" procedure is needed (or an equivalent step to generate the documentation from the embedded doxygen). - The code only compiles on one compiler, but VC++ and Clang support (with the latest C++ standard flags) is expected soon. Compiling and building on Windows 10 is also expected to be supported at that time. Once multiple compilers and desktop environments are tested, development will expand to smaller and more esoteric environments (e.g. Raspberry Pi). - Attention will be devoted to performance bottlenecks as the project matures. From 901fd1b3fb486f3985463591827b04807efe72b0 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 13:10:41 -0700 Subject: [PATCH 04/16] Adding initial CMake files. --- CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..783c1d11 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright 2019 by Cliff Green +# +# https://github.com/connectivecpp/chops-net-ip +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +# CMake 3.8 required for cxx_std_17 target_compile_features + +cmake_minimum_required ( VERSION 3.8 ) + +option ( CHOPS_NET_IP_OPT_BUILD_TESTS "Build and perform chops-net-ip tests" ON ) +option ( CHOPS_NET_IP_OPT_BUILD_EXAMPLES "Build and perform chops-net-ip examples" OFF ) + +project ( chops-net-ip VERSION 1.0 LANGUAGES CXX ) + +set ( package_name "chops-net-ip" ) + +set ( include_source_dir "${CMAKE_SOURCE_DIR}/include" ) + +# Interface library: + +add_library ( ${package_name} INTERFACE ) + +target_include_directories ( ${package_name} INTERFACE ${include_source_dir} ) +target_compile_features ( ${package_name} INTERFACE cxx_std_17) + +if ( CHOPS_NET_IP_OPT_BUILD_TESTS ) + enable_testing() + add_subdirectory ( test ) +endif() + +if ( CHOPS_NET_IP_OPT_BUILD_EXAMPLES ) + enable_testing() + add_subdirectory ( example ) +endif() + +# end of file + From 42c37f7dab82e5c071059f3e3a18b50c0f2701eb Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 14:14:51 -0700 Subject: [PATCH 05/16] Correcting Github to GitHub. --- doc/references.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/references.md b/doc/references.md index 85e5d049..1d6bbe2e 100644 --- a/doc/references.md +++ b/doc/references.md @@ -1,14 +1,14 @@ # Chops Net IP References -- Chris Kohlhoff is a networking expert (among other expertises, including C++), creator of the Asio library and initial author of the C++ Networking Technical Standard (TS). Asio is available at https://think-async.com/ and Chris' Github site is https://github.com/chriskohlhoff/. Asio forms the basis for the C++ Networking Technical Standard (TS), which will (almost surely) be standardized in C++ 20. Currently the Chops Net IP library uses the `networking-ts-impl` repository from Chris' Github account. +- Chris Kohlhoff is a networking expert (among other expertises, including C++), creator of the Asio library and initial author of the C++ Networking Technical Standard (TS). Asio is available at https://think-async.com/ and Chris' GitHub site is https://github.com/chriskohlhoff/. Asio forms the basis for the C++ Networking Technical Standard (TS), which will (almost surely) be standardized in C++ 20. Currently the Chops Net IP library uses the `networking-ts-impl` repository from Chris' GitHub account. -- Vinnie Falco is the author of the Boost Beast library, an excellent building block library for asynchronous (and synchronous) HTTP and WebSocket applications. His Beast library uses Asio. He is proficient in C++ including presenting at CppCon and is also active in blockchain development and other technology areas. His Github site is https://github.com/vinniefalco. While Chops does not currently depend on Beast, the choices and design rationale made by Vinnie in implementing Beast are highly helpful. +- Vinnie Falco is the author of the Boost Beast library, an excellent building block library for asynchronous (and synchronous) HTTP and WebSocket applications. His Beast library uses Asio. He is proficient in C++ including presenting at CppCon and is also active in blockchain development and other technology areas. His GitHub site is https://github.com/vinniefalco. While Chops does not currently depend on Beast, the choices and design rationale made by Vinnie in implementing Beast are highly helpful. - Phil Nash is the author of the Catch C++ unit testing library. The Catch library is available at https://github.com/catchorg/Catch2. - The Boost libraries collection is a high quality set of C++ libraries, available at http://www.boost.org/. -- Kirk Shoop is a C++ expert, particularly in the area of asynchronous design, and has presented multiple times at CppCon. His Github site is https://github.com/kirkshoop. +- Kirk Shoop is a C++ expert, particularly in the area of asynchronous design, and has presented multiple times at CppCon. His GitHub site is https://github.com/kirkshoop. - Diagrams in the documentation are created using the draw.io site at https://www.draw.io/. From c9bc0e9e54c433bd6105c21174d41658232917e3 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 14:15:18 -0700 Subject: [PATCH 06/16] Correcting Github to GitHub. --- doc/release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release.md b/doc/release.md index 16b6e58e..da5258e4 100644 --- a/doc/release.md +++ b/doc/release.md @@ -31,7 +31,7 @@ All tests run, although they are still limited (see next steps and constraints). - The code is well doxygenated, and there is a good start on the high level descriptions, but tutorials and other high-level documentation is needed. A "doxygen to markdown" procedure is needed (or an equivalent step to generate the documentation from the embedded doxygen). - The code only compiles on one compiler, but VC++ and Clang support (with the latest C++ standard flags) is expected soon. Compiling and building on Windows 10 is also expected to be supported at that time. Once multiple compilers and desktop environments are tested, development will expand to smaller and more esoteric environments (e.g. Raspberry Pi). - Attention will be devoted to performance bottlenecks as the project matures. -- The makefiles and build infrastructure components are not yet present. A working CMakeLists.txt is needed as well as Github continuous integration procedures (e.g. Jenkins and Travis). +- The makefiles and build infrastructure components are not yet present. A working CMakeLists.txt is needed as well as GitHub continuous integration procedures (e.g. Jenkins and Travis). - Code coverage tools have not been used on the codebase. ### Overall Comments From 2c34c2bbc8924eab104c0e7c0b8e5ba82ace1a75 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 14:16:00 -0700 Subject: [PATCH 07/16] Initial commit. --- test/CMakeLists.txt | 124 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 test/CMakeLists.txt diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..f4a5466b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,124 @@ +# Copyright 2019 by Cliff Green +# +# https://github.com/connectivecpp/chops-net-ip +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +cmake_minimum_required ( VERSION 3.8 ) + +project ( chops-net-ip-test VERSION 1.0 LANGUAGES CXX ) + +set ( test_source_dir "${CMAKE_SOURCE_DIR}/test" ) +set ( test_main_src "${test_source_dir}/main_test.cpp" ) +set ( test_include_dir "${test_source_dir}/include" ) +set ( tester_suffix "_runner" ) +set ( main_test_lib_name "main_test_lib" ) + +set ( test_sources + "${test_source_dir}/net_ip/basic_io_interface_test.cpp" + "${test_source_dir}/net_ip/basic_net_entity_test.cpp" + "${test_source_dir}/net_ip/endpoints_resolver_test.cpp" + "${test_source_dir}/net_ip/net_ip_error_test.cpp" + "${test_source_dir}/net_ip/net_ip_test.cpp" + "${test_source_dir}/net_ip/shared_utility_func_test.cpp" + "${test_source_dir}/net_ip/shared_utility_test.cpp" + "${test_source_dir}/net_ip/component/error_delivery_test.cpp" + "${test_source_dir}/net_ip/component/io_interface_delivery_test.cpp" + "${test_source_dir}/net_ip/component/send_to_all_test.cpp" + "${test_source_dir}/net_ip/component/simple_variable_len_msg_frame_test.cpp" + "${test_source_dir}/net_ip/detail/io_common_test.cpp" + "${test_source_dir}/net_ip/detail/net_entity_common_test.cpp" + "${test_source_dir}/net_ip/detail/output_queue_test.cpp" + "${test_source_dir}/net_ip/detail/tcp_acceptor_test.cpp" + "${test_source_dir}/net_ip/detail/tcp_connector_test.cpp" + "${test_source_dir}/net_ip/detail/tcp_io_test.cpp" + "${test_source_dir}/net_ip/detail/udp_entity_io_test.cpp" ) + +set ( OPTIONS "" ) +set ( DEFINITIONS "" ) + +set ( header_dirs + "${include_source_dir}" + "${test_include_dir}" + ) + +# Still learning find_package and related ways to bring in third party dependent include directories, +# so don't judge, instead please help. + +set ( catch2_include_dir "${CMAKE_SOURCE_DIR}/../Catch2/single_include" ) +if ( NOT $ENV{CATCH2_INCLUDE_DIR} STREQUAL "" ) + set ( catch2_include_dir $ENV{CATCH2_INCLUDE_DIR}} ) +endif() +set ( utility_rack_include_dir "${CMAKE_SOURCE_DIR}/../utility-rack/include" ) +if ( NOT $ENV{UTILITY_RACK_INCLUDE_DIR} STREQUAL "" ) + set ( utility_rack_include_dir $ENV{UTILITY_RACK_INCLUDE_DIR}} ) +endif() +set ( boost_include_dir "${CMAKE_SOURCE_DIR}/../boost_1_68_0" ) +if ( NOT $ENV{BOOST_INCLUDE_DIR} STREQUAL "" ) + set ( boost_include_dir $ENV{BOOST_INCLUDE_DIR}} ) +endif() +set ( asio_include_dir "${CMAKE_SOURCE_DIR}/../asio/asio/include" ) +if ( NOT $ENV{ASIO_INCLUDE_DIR} STREQUAL "" ) + set ( asio_include_dir $ENV{ASIO_INCLUDE_DIR}} ) +endif() +set ( ring_span_lite_include_dir "${CMAKE_SOURCE_DIR}/../ring-span-lite/include" ) +if ( NOT $ENV{RING_SPAN_LITE_INCLUDE_DIR} STREQUAL "" ) + set ( ring_span_lite_include_dir $ENV{RING_SPAN_LITE_INCLUDE_DIR}} ) +endif() +set ( expected_lite_include_dir "${CMAKE_SOURCE_DIR}/../expected-lite/include" ) +if ( NOT $ENV{EXPECTED_LITE_INCLUDE_DIR} STREQUAL "" ) + set ( expected_lite_include_dir $ENV{EXPECTED_LITE_INCLUDE_DIR}} ) +endif() + +function ( add_target_dependencies target ) +# find_package ( utility-rack REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${utility-rack_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${utility_rack_include_dir} ) +# find_package ( Catch2 REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${Catch2_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${catch2_include_dir} ) +# find_package ( Boost REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${Boost_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${boost_include_dir} ) +# find_package ( asio REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${asio_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${asio_include_dir} ) +# find_package ( ring-span-lite REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${ring-span-lite_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${ring_span_lite_include_dir} ) +# find_package ( expected-lite REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${expected-lite_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${expected_lite_include_dir} ) +endfunction() + +function ( add_target_info target ) + target_compile_features ( ${target} PRIVATE cxx_std_17 ) + target_compile_options ( ${target} PRIVATE ${OPTIONS} ) + target_compile_definitions ( ${target} PRIVATE ${DEFINITIONS} ) + target_include_directories ( ${target} PRIVATE ${header_dirs} ) + add_target_dependencies ( ${target} ) +endfunction() + +add_library ( ${main_test_lib_name} STATIC ${test_main_src} ) +add_target_info ( ${main_test_lib_name} ) + +function ( make_exe target src ) + add_executable ( ${target} ${src} ) + add_target_info ( ${target} ) + target_link_libraries ( ${target} PRIVATE pthread ) + target_link_libraries ( ${target} PRIVATE ${main_test_lib_name} ) + message ( "Test executable to create: ${target}" ) + add_test ( NAME ${target}${tester_suffix} COMMAND ${target} ) +endfunction() + +enable_testing() + +foreach ( test_src IN LISTS test_sources ) + get_filename_component ( targ ${test_src} NAME_WE ) + message ( "Calling make_exe for: ${targ}" ) + make_exe ( ${targ} ${test_src} ) +endforeach() + +# end of file + From a122ec088802598c7b20ca20c56434cc531e7f0d Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 14:16:31 -0700 Subject: [PATCH 08/16] Correcting Catch2 include to use single header include. --- test/main_test.cpp | 4 ++-- test/net_ip/basic_io_interface_test.cpp | 2 +- test/net_ip/basic_net_entity_test.cpp | 2 +- test/net_ip/component/error_delivery_test.cpp | 2 +- test/net_ip/component/io_interface_delivery_test.cpp | 2 +- test/net_ip/component/send_to_all_test.cpp | 2 +- test/net_ip/component/simple_variable_len_msg_frame_test.cpp | 2 +- test/net_ip/detail/io_common_test.cpp | 2 +- test/net_ip/detail/net_entity_common_test.cpp | 2 +- test/net_ip/detail/output_queue_test.cpp | 2 +- test/net_ip/detail/tcp_acceptor_test.cpp | 2 +- test/net_ip/detail/tcp_connector_test.cpp | 2 +- test/net_ip/detail/tcp_io_test.cpp | 2 +- test/net_ip/detail/udp_entity_io_test.cpp | 2 +- test/net_ip/endpoints_resolver_test.cpp | 2 +- test/net_ip/net_ip_error_test.cpp | 2 +- test/net_ip/net_ip_test.cpp | 2 +- test/net_ip/shared_utility_func_test.cpp | 2 +- test/net_ip/shared_utility_test.cpp | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/main_test.cpp b/test/main_test.cpp index a534f4d7..268b44e9 100644 --- a/test/main_test.cpp +++ b/test/main_test.cpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -17,5 +17,5 @@ #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include "catch2/catch.hpp" diff --git a/test/net_ip/basic_io_interface_test.cpp b/test/net_ip/basic_io_interface_test.cpp index 50069bc2..cdc40881 100644 --- a/test/net_ip/basic_io_interface_test.cpp +++ b/test/net_ip/basic_io_interface_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // std::shared_ptr #include diff --git a/test/net_ip/basic_net_entity_test.cpp b/test/net_ip/basic_net_entity_test.cpp index 0ddcaba5..b88eda9d 100644 --- a/test/net_ip/basic_net_entity_test.cpp +++ b/test/net_ip/basic_net_entity_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // endpoint declarations diff --git a/test/net_ip/component/error_delivery_test.cpp b/test/net_ip/component/error_delivery_test.cpp index f2bb0499..6613f818 100644 --- a/test/net_ip/component/error_delivery_test.cpp +++ b/test/net_ip/component/error_delivery_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // std::size_t #include diff --git a/test/net_ip/component/io_interface_delivery_test.cpp b/test/net_ip/component/io_interface_delivery_test.cpp index 35274ff1..59260f68 100644 --- a/test/net_ip/component/io_interface_delivery_test.cpp +++ b/test/net_ip/component/io_interface_delivery_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/component/send_to_all_test.cpp b/test/net_ip/component/send_to_all_test.cpp index 89888cd9..22832937 100644 --- a/test/net_ip/component/send_to_all_test.cpp +++ b/test/net_ip/component/send_to_all_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // std::size_t diff --git a/test/net_ip/component/simple_variable_len_msg_frame_test.cpp b/test/net_ip/component/simple_variable_len_msg_frame_test.cpp index bb88626a..d69a90cf 100644 --- a/test/net_ip/component/simple_variable_len_msg_frame_test.cpp +++ b/test/net_ip/component/simple_variable_len_msg_frame_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include diff --git a/test/net_ip/detail/io_common_test.cpp b/test/net_ip/detail/io_common_test.cpp index 0023ba1f..695afae3 100644 --- a/test/net_ip/detail/io_common_test.cpp +++ b/test/net_ip/detail/io_common_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // endpoint declarations #include diff --git a/test/net_ip/detail/net_entity_common_test.cpp b/test/net_ip/detail/net_entity_common_test.cpp index cf28ea68..8be17077 100644 --- a/test/net_ip/detail/net_entity_common_test.cpp +++ b/test/net_ip/detail/net_entity_common_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // std::shared_ptr #include // std::error_code diff --git a/test/net_ip/detail/output_queue_test.cpp b/test/net_ip/detail/output_queue_test.cpp index 08295506..a4b5b2ff 100644 --- a/test/net_ip/detail/output_queue_test.cpp +++ b/test/net_ip/detail/output_queue_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include // std::move diff --git a/test/net_ip/detail/tcp_acceptor_test.cpp b/test/net_ip/detail/tcp_acceptor_test.cpp index 0c562d4a..5f3c2110 100644 --- a/test/net_ip/detail/tcp_acceptor_test.cpp +++ b/test/net_ip/detail/tcp_acceptor_test.cpp @@ -18,7 +18,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/detail/tcp_connector_test.cpp b/test/net_ip/detail/tcp_connector_test.cpp index 58bfe38d..e06571ef 100644 --- a/test/net_ip/detail/tcp_connector_test.cpp +++ b/test/net_ip/detail/tcp_connector_test.cpp @@ -16,7 +16,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/detail/tcp_io_test.cpp b/test/net_ip/detail/tcp_io_test.cpp index 4139ab2e..0d753eea 100644 --- a/test/net_ip/detail/tcp_io_test.cpp +++ b/test/net_ip/detail/tcp_io_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/detail/udp_entity_io_test.cpp b/test/net_ip/detail/udp_entity_io_test.cpp index e1ecdccf..877abb17 100644 --- a/test/net_ip/detail/udp_entity_io_test.cpp +++ b/test/net_ip/detail/udp_entity_io_test.cpp @@ -18,7 +18,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/endpoints_resolver_test.cpp b/test/net_ip/endpoints_resolver_test.cpp index 75016d00..5ada7680 100644 --- a/test/net_ip/endpoints_resolver_test.cpp +++ b/test/net_ip/endpoints_resolver_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/net_ip_error_test.cpp b/test/net_ip/net_ip_error_test.cpp index 352663bd..29408760 100644 --- a/test/net_ip/net_ip_error_test.cpp +++ b/test/net_ip/net_ip_error_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include diff --git a/test/net_ip/net_ip_test.cpp b/test/net_ip/net_ip_test.cpp index 8e41a22d..5e8544e2 100644 --- a/test/net_ip/net_ip_test.cpp +++ b/test/net_ip/net_ip_test.cpp @@ -13,7 +13,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include diff --git a/test/net_ip/shared_utility_func_test.cpp b/test/net_ip/shared_utility_func_test.cpp index 29b2c523..1011ca54 100644 --- a/test/net_ip/shared_utility_func_test.cpp +++ b/test/net_ip/shared_utility_func_test.cpp @@ -14,7 +14,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include diff --git a/test/net_ip/shared_utility_test.cpp b/test/net_ip/shared_utility_test.cpp index d44f9467..e4eb8872 100644 --- a/test/net_ip/shared_utility_test.cpp +++ b/test/net_ip/shared_utility_test.cpp @@ -19,7 +19,7 @@ * */ -#include "catch.hpp" +#include "catch2/catch.hpp" #include #include // std::size_t, std::byte From 233c67084277ec248551f0a1dcdaa86628f6799e Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 14:19:32 -0700 Subject: [PATCH 09/16] CMake cleanup. --- bld/CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 bld/CMakeLists.txt diff --git a/bld/CMakeLists.txt b/bld/CMakeLists.txt deleted file mode 100644 index 6cb00c2f..00000000 --- a/bld/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -cmake_minimum_required (VERSION 3.4) -project (chops) - -target_compile_features(chops PUBLIC cxx_std_17) - -include_directories("${PROJECT_BINARY_DIR}") - -# add the executables -add_executable(WaitQueueTest wait_queue_test.cpp) -add_executable(RepeatTest repeat_test.cpp) From 86484dfe1261c0412f6c60bfc0c688d6cd78a4d3 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 16:54:46 -0700 Subject: [PATCH 10/16] Changing from Networking TS to Asio. --- include/net_ip/basic_io_interface.hpp | 32 +++++------ include/net_ip/basic_net_entity.hpp | 6 +-- include/net_ip/component/error_delivery.hpp | 4 +- include/net_ip/component/io_state_change.hpp | 12 ++--- .../simple_variable_len_msg_frame.hpp | 6 +-- include/net_ip/component/worker.hpp | 18 +++---- include/net_ip/detail/io_common.hpp | 5 +- include/net_ip/detail/tcp_acceptor.hpp | 21 ++++---- include/net_ip/detail/tcp_connector.hpp | 45 ++++++++-------- include/net_ip/detail/tcp_io.hpp | 49 ++++++++--------- include/net_ip/detail/udp_entity_io.hpp | 29 +++++----- include/net_ip/endpoints_resolver.hpp | 30 +++++------ include/net_ip/net_ip.hpp | 53 ++++++++++--------- .../net_ip/shared_utility_func_test.hpp | 6 +-- test/include/net_ip/shared_utility_test.hpp | 15 +++--- test/net_ip/basic_net_entity_test.cpp | 4 +- .../simple_variable_len_msg_frame_test.cpp | 10 ++-- test/net_ip/detail/io_common_test.cpp | 8 +-- test/net_ip/detail/output_queue_test.cpp | 17 +++--- test/net_ip/detail/tcp_acceptor_test.cpp | 33 ++++++------ test/net_ip/detail/tcp_connector_test.cpp | 12 ++--- test/net_ip/detail/tcp_io_test.cpp | 19 ++++--- test/net_ip/detail/udp_entity_io_test.cpp | 9 ++-- test/net_ip/endpoints_resolver_test.cpp | 23 ++++---- test/net_ip/net_ip_test.cpp | 6 --- test/net_ip/shared_utility_func_test.cpp | 10 ++-- test/net_ip/shared_utility_test.cpp | 30 +++++------ 27 files changed, 242 insertions(+), 270 deletions(-) diff --git a/include/net_ip/basic_io_interface.hpp b/include/net_ip/basic_io_interface.hpp index 01450d2e..3d0ab086 100644 --- a/include/net_ip/basic_io_interface.hpp +++ b/include/net_ip/basic_io_interface.hpp @@ -228,7 +228,7 @@ class basic_io_interface { * * @param sz Size of buffer. * - * @param endp Destination @c std::experimental::net::ip::udp::endpoint for the buffer. + * @param endp Destination @c asio::ip::udp::endpoint for the buffer. * * @throw A @c net_ip_exception is thrown if there is not an associated IO handler. */ @@ -244,7 +244,7 @@ class basic_io_interface { * * @param buf @c chops::const_shared_buffer containing data. * - * @param endp Destination @c std::experimental::net::ip::udp::endpoint for the buffer. + * @param endp Destination @c asio::ip::udp::endpoint for the buffer. * * @throw A @c net_ip_exception is thrown if there is not an associated IO handler. */ @@ -265,7 +265,7 @@ class basic_io_interface { * * @param buf @c chops::mutable_shared_buffer containing data. * - * @param endp Destination @c std::experimental::net::ip::udp::endpoint for the buffer. + * @param endp Destination @c asio::ip::udp::endpoint for the buffer. * * @throw A @c net_ip_exception is thrown if there is not an associated IO handler. */ @@ -298,9 +298,9 @@ class basic_io_interface { * the callback is: * * @code - * bool (std::experimental::net::const_buffer, + * bool (asio::const_buffer, * chops::net::tcp_io_interface, // basic_io_interface - * std::experimental::net::ip::tcp::endpoint); + * asio::ip::tcp::endpoint); * @endcode * * The buffer (first parameter) always references a full message. The @@ -318,7 +318,7 @@ class basic_io_interface { * the callback is: * * @code - * std::size_t (std::experimental::net::mutable_buffer); + * std::size_t (asio::mutable_buffer); * @endcode * * Each time the message frame callback is called by the Chops Net IP IO handler, the @@ -370,9 +370,9 @@ class basic_io_interface { * the callback is: * * @code - * bool (std::experimental::net::const_buffer, + * bool (asio::const_buffer, * chops::net::tcp_io_interface, // basic_io_interface - * std::experimental::net::ip::tcp::endpoint); + * asio::ip::tcp::endpoint); * @endcode * * The buffer points to the complete message including the delimiter sequence. The @@ -418,13 +418,13 @@ class basic_io_interface { * * @code * // TCP io: - * bool (std::experimental::net::const_buffer, + * bool (asio::const_buffer, * chops::net::tcp_io_interface, // basic_io_interface - * std::experimental::net::ip::tcp::endpoint); + * asio::ip::tcp::endpoint); * // UDP io: - * bool (std::experimental::net::const_buffer, + * bool (asio::const_buffer, * chops::net::udp_io_interface, // basic_io_interface - * std::experimental::net::ip::udp::endpoint); + * asio::ip::udp::endpoint); * @endcode * * Returning @c false from the message handler callback causes the TCP connection or UDP socket to @@ -461,7 +461,7 @@ class basic_io_interface { * * Sends (writes) are enabled after this call. * - * @param endp Default destination @c std::experimental::net::ip::udp::endpoint. + * @param endp Default destination @c asio::ip::udp::endpoint. * * @param max_size Maximum UDP datagram size. * @@ -469,9 +469,9 @@ class basic_io_interface { * the callback is: * * @code - * bool (std::experimental::net::const_buffer, + * bool (asio::const_buffer, * chops::net::udp_io_interface, // basic_io_interface - * std::experimental::net::ip::udp::endpoint); + * asio::ip::udp::endpoint); * @endcode * * Returning @c false from the message handler callback causes the UDP socket to @@ -530,7 +530,7 @@ class basic_io_interface { * This method is used to enable IO processing where only sends are needed (and no * incoming message handling). * - * @param endp Default destination @c std::experimental::net::ip::udp::endpoint. + * @param endp Default destination @c asio::ip::udp::endpoint. * * @return @c false if already started, otherwise @c true. * diff --git a/include/net_ip/basic_net_entity.hpp b/include/net_ip/basic_net_entity.hpp index 9aa4eace..fc61037e 100644 --- a/include/net_ip/basic_net_entity.hpp +++ b/include/net_ip/basic_net_entity.hpp @@ -6,7 +6,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -122,8 +122,8 @@ class basic_net_entity { * The socket reference returned from this method allows direct access to the * @c basic_net_entity socket. This socket may be different from the socket that is * accessible through the @c basic_io_interface object. In particular, a TCP acceptor - * socket reference is of type @c ip::tcp::acceptor (in the namespace - * @c std::experimental::net), a TCP connector socket reference is of type + * socket reference is of type @c ip::tcp::acceptor (in the @c asio namespace), a + * TCP connector socket reference is of type * @c ip::tcp::socket, and a UDP entity socket reference is of type * @c ip::udp::socket. * diff --git a/include/net_ip/component/error_delivery.hpp b/include/net_ip/component/error_delivery.hpp index f95c07a9..a6f72850 100644 --- a/include/net_ip/component/error_delivery.hpp +++ b/include/net_ip/component/error_delivery.hpp @@ -6,7 +6,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -66,7 +66,7 @@ inline void udp_empty_error_func(udp_io_interface, std::error_code) { } * is likely to soon go away. Instead, a @c void pointer of the underlying * handler is used. Another reason for not storing a @c basic_io_interface is that * the IO handler type parameterization is no longer needed, so this can be used for - * both TCP and UDP error data. + * both TCP and UDP error data. The pointer address is used for logging purposes only. */ struct error_data { std::chrono::steady_clock::time_point time_p; diff --git a/include/net_ip/component/io_state_change.hpp b/include/net_ip/component/io_state_change.hpp index 98452ea9..b8850e56 100644 --- a/include/net_ip/component/io_state_change.hpp +++ b/include/net_ip/component/io_state_change.hpp @@ -22,7 +22,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -35,7 +35,7 @@ #include // std::size_t, std::byte #include // std::move -#include // ip::udp::endpoint +#include "asio/ip/udp.hpp" // ip::udp::endpoint #include "net_ip/io_interface.hpp" @@ -172,7 +172,7 @@ auto make_send_only_io_state_change () { * @brief Create an IO state change function object parameters for UDP senders and * receivers with a default destination endpoint. * - * @param endp Default destination @c std::experimental::net::ip::udp::endpoint. + * @param endp Default destination @c asio::ip::udp::endpoint. * * @param max_size Maximum buffer size for UDP reads. * @@ -185,7 +185,7 @@ auto make_send_only_io_state_change () { */ template -auto make_default_endp_io_state_change (std::experimental::net::ip::udp::endpoint endp, +auto make_default_endp_io_state_change (asio::ip::udp::endpoint endp, std::size_t max_size, MH&& msg_hdlr) { return [max_size, endp, mh = std::move(msg_hdlr)] @@ -200,13 +200,13 @@ auto make_default_endp_io_state_change (std::experimental::net::ip::udp::endpoin * @brief Create an IO state change function object parameters for UDP sending only * with a default destination endpoint. * - * @param endp Default destination @c std::experimental::net::ip::udp::endpoint. + * @param endp Default destination @c asio::ip::udp::endpoint. * * @return A function object that can be used with the @c start method. * * @note This is implemented only for UDP processing. */ -auto make_send_only_default_endp_io_state_change (std::experimental::net::ip::udp::endpoint endp) { +auto make_send_only_default_endp_io_state_change (asio::ip::udp::endpoint endp) { return [endp] (udp_io_interface io, std::size_t num, bool starting) mutable { if (starting) { io.start_io(endp); diff --git a/include/net_ip/component/simple_variable_len_msg_frame.hpp b/include/net_ip/component/simple_variable_len_msg_frame.hpp index 8d184880..9780d794 100644 --- a/include/net_ip/component/simple_variable_len_msg_frame.hpp +++ b/include/net_ip/component/simple_variable_len_msg_frame.hpp @@ -15,7 +15,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -27,7 +27,7 @@ #include // std::size_t, std::byte -#include +#include "asio/buffer.hpp" namespace chops { namespace net { @@ -59,7 +59,7 @@ using hdr_decoder_func = std::size_t (*)(const std::byte* ptr, std::size_t sz); inline auto make_simple_variable_len_msg_frame(hdr_decoder_func func) { bool hdr_processed = false; return [hdr_processed, func] - (std::experimental::net::mutable_buffer buf) mutable -> std::size_t { + (asio::mutable_buffer buf) mutable -> std::size_t { return hdr_processed ? (hdr_processed = false, 0) : (hdr_processed = true, func(static_cast(buf.data()), buf.size())); diff --git a/include/net_ip/component/worker.hpp b/include/net_ip/component/worker.hpp index 68fbf7f0..1cbc663b 100644 --- a/include/net_ip/component/worker.hpp +++ b/include/net_ip/component/worker.hpp @@ -24,8 +24,9 @@ #include #include -#include -#include +#include "asio/io_context.hpp" +#include "asio/executor.hpp" +#include "asio/executor_work_guard.hpp" namespace chops { namespace net { @@ -39,20 +40,19 @@ namespace net { */ class worker { private: - std::experimental::net::io_context m_ioc; - std::experimental::net::executor_work_guard - m_wg; - std::thread m_run_thr; + asio::io_context m_ioc; + asio::executor_work_guard m_wg; + std::thread m_run_thr; public: - worker() : m_ioc(), m_wg(std::experimental::net::make_work_guard(m_ioc)), m_run_thr() { } + worker() : m_ioc(), m_wg(asio::make_work_guard(m_ioc)), m_run_thr() { } /** * @brief Provide access to the @c io_context. * - * @return Reference to a @c std::experimental::net::io_context. + * @return Reference to a @c asio::io_context. */ - std::experimental::net::io_context& get_io_context() { return m_ioc; } + asio::io_context& get_io_context() { return m_ioc; } /** * @brief Start the thread that invokes the underlying asynchronous diff --git a/include/net_ip/detail/io_common.hpp b/include/net_ip/detail/io_common.hpp index 0f52f926..3dd661ef 100644 --- a/include/net_ip/detail/io_common.hpp +++ b/include/net_ip/detail/io_common.hpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -23,9 +23,6 @@ #include // std::function, used for type erased notifications to net_entity objects #include // std::shared_ptr -#include -#include - #include "net_ip/detail/output_queue.hpp" #include "net_ip/queue_stats.hpp" #include "utility/shared_buffer.hpp" diff --git a/include/net_ip/detail/tcp_acceptor.hpp b/include/net_ip/detail/tcp_acceptor.hpp index 15e5337c..6bdbb138 100644 --- a/include/net_ip/detail/tcp_acceptor.hpp +++ b/include/net_ip/detail/tcp_acceptor.hpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,9 +18,8 @@ #ifndef TCP_ACCEPTOR_HPP_INCLUDED #define TCP_ACCEPTOR_HPP_INCLUDED -#include -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/io_context.hpp" #include #include @@ -42,20 +41,21 @@ namespace detail { class tcp_acceptor : public std::enable_shared_from_this { public: - using socket_type = std::experimental::net::ip::tcp::acceptor; - using endpoint_type = std::experimental::net::ip::tcp::endpoint; + using socket_type = asio::ip::tcp::acceptor; + using endpoint_type = asio::ip::tcp::endpoint; private: net_entity_common m_entity_common; + asio::io_context& m_io_context; socket_type m_acceptor; std::vector m_io_handlers; endpoint_type m_acceptor_endp; bool m_reuse_addr; public: - tcp_acceptor(std::experimental::net::io_context& ioc, const endpoint_type& endp, + tcp_acceptor(asio::io_context& ioc, const endpoint_type& endp, bool reuse_addr) : - m_entity_common(), m_acceptor(ioc), m_io_handlers(), m_acceptor_endp(endp), + m_entity_common(), m_io_context(ioc), m_acceptor(ioc), m_io_handlers(), m_acceptor_endp(endp), m_reuse_addr(reuse_addr) { } private: @@ -78,8 +78,7 @@ class tcp_acceptor : public std::enable_shared_from_this { return false; } try { - m_acceptor = socket_type(m_acceptor.get_executor().context(), m_acceptor_endp, - m_reuse_addr); + m_acceptor = socket_type(m_io_context, m_acceptor_endp, m_reuse_addr); } catch (const std::system_error& se) { m_entity_common.call_error_cb(tcp_io_ptr(), se.code()); @@ -112,7 +111,7 @@ class tcp_acceptor : public std::enable_shared_from_this { auto self = shared_from_this(); m_acceptor.async_accept( [this, self] - (const std::error_code& err, std::experimental::net::ip::tcp::socket sock) mutable { + (const std::error_code& err, asio::ip::tcp::socket sock) mutable { if (err) { m_entity_common.call_error_cb(tcp_io_ptr(), err); stop(); // is this the right thing to do? what are possible causes of errors? diff --git a/include/net_ip/detail/tcp_connector.hpp b/include/net_ip/detail/tcp_connector.hpp index 719998df..b7c20a14 100644 --- a/include/net_ip/detail/tcp_connector.hpp +++ b/include/net_ip/detail/tcp_connector.hpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,11 +18,11 @@ #ifndef TCP_CONNECTOR_HPP_INCLUDED #define TCP_CONNECTOR_HPP_INCLUDED -#include -#include -#include -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/connect.hpp" +#include "asio/io_context.hpp" +#include "asio/ip/basic_resolver.hpp" +#include "asio/steady_timer.hpp" #include #include @@ -45,26 +45,25 @@ namespace detail { class tcp_connector : public std::enable_shared_from_this { public: - using socket_type = std::experimental::net::ip::tcp::socket; - using endpoint_type = std::experimental::net::ip::tcp::endpoint; + using socket_type = asio::ip::tcp::socket; + using endpoint_type = asio::ip::tcp::endpoint; private: - using resolver_type = chops::net::endpoints_resolver; - using resolver_results = - std::experimental::net::ip::basic_resolver_results; + using resolver_type = chops::net::endpoints_resolver; + using resolver_results = asio::ip::basic_resolver_results; using endpoints = std::vector; using endpoints_iter = endpoints::const_iterator; private: - net_entity_common m_entity_common; - socket_type m_socket; - tcp_io_ptr m_io_handler; - resolver_type m_resolver; - endpoints m_endpoints; - std::experimental::net::steady_timer m_timer; - std::chrono::milliseconds m_reconn_time; - std::string m_remote_host; - std::string m_remote_port; + net_entity_common m_entity_common; + socket_type m_socket; + tcp_io_ptr m_io_handler; + resolver_type m_resolver; + endpoints m_endpoints; + asio::steady_timer m_timer; + std::chrono::milliseconds m_reconn_time; + std::string m_remote_host; + std::string m_remote_port; // TODO: currently this flag is needed to distinguish whether a connect // handler can't connect or whether the operation is cancelled and it's @@ -73,7 +72,7 @@ class tcp_connector : public std::enable_shared_from_this { public: template - tcp_connector(std::experimental::net::io_context& ioc, + tcp_connector(asio::io_context& ioc, Iter beg, Iter end, std::chrono::milliseconds reconn_time) : m_entity_common(), m_socket(ioc), @@ -87,7 +86,7 @@ class tcp_connector : public std::enable_shared_from_this { m_shutting_down(false) { } - tcp_connector(std::experimental::net::io_context& ioc, + tcp_connector(asio::io_context& ioc, std::string_view remote_port, std::string_view remote_host, std::chrono::milliseconds reconn_time) : m_entity_common(), @@ -182,7 +181,7 @@ class tcp_connector : public std::enable_shared_from_this { void start_connect() { auto self = shared_from_this(); - std::experimental::net::async_connect(m_socket, m_endpoints.cbegin(), m_endpoints.cend(), + asio::async_connect(m_socket, m_endpoints.cbegin(), m_endpoints.cend(), [this, self] (const std::error_code& err, endpoints_iter iter) mutable { handle_connect(err, iter); diff --git a/include/net_ip/detail/tcp_io.hpp b/include/net_ip/detail/tcp_io.hpp index df580949..60f240da 100644 --- a/include/net_ip/detail/tcp_io.hpp +++ b/include/net_ip/detail/tcp_io.hpp @@ -18,9 +18,13 @@ #ifndef TCP_IO_HPP_INCLUDED #define TCP_IO_HPP_INCLUDED -#include -#include -#include +#include "asio/io_context.hpp" +#include "asio/executor.hpp" +#include "asio/read.hpp" +#include "asio/read_until.hpp" +#include "asio/write.hpp" +#include "asio/ip/tcp.hpp" +#include "asio/buffer.hpp" #include // std::shared_ptr, std::enable_shared_from_this #include @@ -42,12 +46,12 @@ namespace chops { namespace net { namespace detail { -std::size_t null_msg_frame (std::experimental::net::mutable_buffer) noexcept; +std::size_t null_msg_frame (asio::mutable_buffer) noexcept; class tcp_io : public std::enable_shared_from_this { public: - using socket_type = std::experimental::net::ip::tcp::socket; - using endpoint_type = std::experimental::net::ip::tcp::endpoint; + using socket_type = asio::ip::tcp::socket; + using endpoint_type = asio::ip::tcp::endpoint; using entity_notifier_cb = std::function)>; private: @@ -98,7 +102,7 @@ class tcp_io : public std::enable_shared_from_this { } m_read_size = header_size; m_byte_vec.resize(m_read_size); - start_read(std::experimental::net::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()), + start_read(asio::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()), std::forward(msg_handler), std::forward(msg_frame)); return true; } @@ -120,8 +124,8 @@ class tcp_io : public std::enable_shared_from_this { bool start_io() { return start_io(1, - [] (std::experimental::net::const_buffer, basic_io_interface, - std::experimental::net::ip::tcp::endpoint) mutable { + [] (asio::const_buffer, basic_io_interface, + asio::ip::tcp::endpoint) mutable { return true; }, null_msg_frame @@ -166,7 +170,7 @@ class tcp_io : public std::enable_shared_from_this { // post(m_socket.get_executor(), [this, self] { // attempt graceful shutdown std::error_code ec; - m_socket.shutdown(std::experimental::net::ip::tcp::socket::shutdown_both, ec); + m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ec); // auto self { shared_from_this() }; // post(m_socket.get_executor(), [this, self, ec] () mutable { m_socket.close(ec); @@ -189,11 +193,11 @@ class tcp_io : public std::enable_shared_from_this { } template - void start_read(std::experimental::net::mutable_buffer mbuf, MH&& msg_hdlr, MF&& msg_frame) { + void start_read(asio::mutable_buffer mbuf, MH&& msg_hdlr, MF&& msg_frame) { // std::move in lambda instead of std::forward since an explicit copy or move of the function // object is desired so there are no dangling references auto self { shared_from_this() }; - std::experimental::net::async_read(m_socket, mbuf, + asio::async_read(m_socket, mbuf, [this, self, mbuf, mh = std::move(msg_hdlr), mf = std::move(msg_frame)] (const std::error_code& err, std::size_t nb) mutable { handle_read(mbuf, err, nb, std::move(mh), std::move(mf)); @@ -202,15 +206,13 @@ class tcp_io : public std::enable_shared_from_this { } template - void handle_read(std::experimental::net::mutable_buffer, + void handle_read(asio::mutable_buffer, const std::error_code&, std::size_t, MH&&, MF&&); template void start_read_until(MH&& msg_hdlr) { auto self { shared_from_this() }; - std::experimental::net::async_read_until(m_socket, - std::experimental::net::dynamic_buffer(m_byte_vec), - m_delimiter, + asio::async_read_until(m_socket, asio::dynamic_buffer(m_byte_vec), m_delimiter, [this, self, mh = std::move(msg_hdlr)] (const std::error_code& err, std::size_t nb) mutable { handle_read_until(err, nb, std::move(mh)); } @@ -229,7 +231,7 @@ class tcp_io : public std::enable_shared_from_this { // method implementations, just to make the class declaration a little more readable template -void tcp_io::handle_read(std::experimental::net::mutable_buffer mbuf, +void tcp_io::handle_read(asio::mutable_buffer mbuf, const std::error_code& err, std::size_t /* num_bytes */, MH&& msg_hdlr, MF&& msg_frame) { @@ -240,7 +242,7 @@ void tcp_io::handle_read(std::experimental::net::mutable_buffer mbuf, // assert num_bytes == mbuf.size() std::size_t next_read_size = msg_frame(mbuf); if (next_read_size == 0) { // msg fully received, now invoke message handler - if (!msg_hdlr(std::experimental::net::const_buffer(m_byte_vec.data(), m_byte_vec.size()), + if (!msg_hdlr(asio::const_buffer(m_byte_vec.data(), m_byte_vec.size()), basic_io_interface(weak_from_this()), m_remote_endp)) { // message handler not happy, tear everything down m_notifier_cb(std::make_error_code(net_ip_errc::message_handler_terminated), @@ -248,12 +250,12 @@ void tcp_io::handle_read(std::experimental::net::mutable_buffer mbuf, return; } m_byte_vec.resize(m_read_size); - mbuf = std::experimental::net::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()); + mbuf = asio::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()); } else { std::size_t old_size = m_byte_vec.size(); m_byte_vec.resize(old_size + next_read_size); - mbuf = std::experimental::net::mutable_buffer(m_byte_vec.data() + old_size, next_read_size); + mbuf = asio::mutable_buffer(m_byte_vec.data() + old_size, next_read_size); } start_read(mbuf, std::forward(msg_hdlr), std::forward(msg_frame)); } @@ -266,7 +268,7 @@ void tcp_io::handle_read_until(const std::error_code& err, std::size_t num_bytes return; } // beginning of m_byte_vec to num_bytes is buf, includes delimiter bytes - if (!msg_hdlr(std::experimental::net::const_buffer(m_byte_vec.data(), num_bytes), + if (!msg_hdlr(asio::const_buffer(m_byte_vec.data(), num_bytes), basic_io_interface(weak_from_this()), m_remote_endp)) { m_notifier_cb(std::make_error_code(net_ip_errc::message_handler_terminated), shared_from_this()); @@ -279,8 +281,7 @@ void tcp_io::handle_read_until(const std::error_code& err, std::size_t num_bytes inline void tcp_io::start_write(chops::const_shared_buffer buf) { auto self { shared_from_this() }; - std::experimental::net::async_write(m_socket, - std::experimental::net::const_buffer(buf.data(), buf.size()), + asio::async_write(m_socket, asio::const_buffer(buf.data(), buf.size()), [this, self] (const std::error_code& err, std::size_t nb) { handle_write(err, nb); } @@ -302,7 +303,7 @@ inline void tcp_io::handle_write(const std::error_code& err, std::size_t /* num_ using tcp_io_ptr = std::shared_ptr; -inline std::size_t null_msg_frame (std::experimental::net::mutable_buffer) noexcept { +inline std::size_t null_msg_frame (asio::mutable_buffer) noexcept { return 0; } diff --git a/include/net_ip/detail/udp_entity_io.hpp b/include/net_ip/detail/udp_entity_io.hpp index 3d082834..3e55cfd6 100644 --- a/include/net_ip/detail/udp_entity_io.hpp +++ b/include/net_ip/detail/udp_entity_io.hpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,10 +18,10 @@ #ifndef UDP_ENTITY_IO_HPP_INCLUDED #define UDP_ENTITY_IO_HPP_INCLUDED -#include -#include -#include -#include +#include "asio/io_context.hpp" +#include "asio/executor.hpp" +#include "asio/ip/udp.hpp" +#include "asio/buffer.hpp" #include // std::shared_ptr, std::enable_shared_from_this #include @@ -44,8 +44,8 @@ namespace detail { class udp_entity_io : public std::enable_shared_from_this { public: - using socket_type = std::experimental::net::ip::udp::socket; - using endpoint_type = std::experimental::net::ip::udp::endpoint; + using socket_type = asio::ip::udp::socket; + using endpoint_type = asio::ip::udp::endpoint; private: using byte_vec = chops::mutable_shared_buffer::byte_vec; @@ -54,6 +54,7 @@ class udp_entity_io : public std::enable_shared_from_this { io_common m_io_common; net_entity_common m_entity_common; + asio::io_context& m_io_context; socket_type m_socket; endpoint_type m_local_endp; endpoint_type m_default_dest_endp; @@ -66,9 +67,9 @@ class udp_entity_io : public std::enable_shared_from_this { endpoint_type m_sender_endp; public: - udp_entity_io(std::experimental::net::io_context& ioc, + udp_entity_io(asio::io_context& ioc, const endpoint_type& local_endp) noexcept : - m_io_common(), m_entity_common(), + m_io_common(), m_entity_common(), m_io_context(ioc), m_socket(ioc), m_local_endp(local_endp), m_default_dest_endp(), m_byte_vec(), m_max_size(0), m_sender_endp() { } @@ -104,10 +105,10 @@ class udp_entity_io : public std::enable_shared_from_this { // assume default constructed endpoints compare equal if (m_local_endp == endpoint_type()) { // TODO: this needs to be changed, doesn't allow sending to an ipV6 endpoint - m_socket.open(std::experimental::net::ip::udp::v4()); + m_socket.open(asio::ip::udp::v4()); } else { - m_socket = socket_type(m_socket.get_executor().context(), m_local_endp); + m_socket = socket_type(m_io_context, m_local_endp); } } catch (const std::system_error& se) { @@ -204,7 +205,7 @@ class udp_entity_io : public std::enable_shared_from_this { auto self { shared_from_this() }; m_byte_vec.resize(m_max_size); m_socket.async_receive_from( - std::experimental::net::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()), + asio::mutable_buffer(m_byte_vec.data(), m_byte_vec.size()), m_sender_endp, [this, self, mh = std::move(msg_hdlr)] (const std::error_code& err, std::size_t nb) mutable { @@ -236,7 +237,7 @@ void udp_entity_io::handle_read(const std::error_code& err, std::size_t num_byte stop(); return; } - if (!msg_hdlr(std::experimental::net::const_buffer(m_byte_vec.data(), num_bytes), + if (!msg_hdlr(asio::const_buffer(m_byte_vec.data(), num_bytes), basic_io_interface(weak_from_this()), m_sender_endp)) { // message handler not happy, tear everything down err_notify(std::make_error_code(net_ip_errc::message_handler_terminated)); @@ -248,7 +249,7 @@ void udp_entity_io::handle_read(const std::error_code& err, std::size_t num_byte inline void udp_entity_io::start_write(chops::const_shared_buffer buf, const endpoint_type& endp) { auto self { shared_from_this() }; - m_socket.async_send_to(std::experimental::net::const_buffer(buf.data(), buf.size()), endp, + m_socket.async_send_to(asio::const_buffer(buf.data(), buf.size()), endp, [this, self] (const std::error_code& err, std::size_t nb) { handle_write(err, nb); } diff --git a/include/net_ip/endpoints_resolver.hpp b/include/net_ip/endpoints_resolver.hpp index b2decf57..51d90adb 100644 --- a/include/net_ip/endpoints_resolver.hpp +++ b/include/net_ip/endpoints_resolver.hpp @@ -20,8 +20,8 @@ #ifndef ENDPOINTS_RESOLVER_HPP_INCLUDED #define ENDPOINTS_RESOLVER_HPP_INCLUDED -#include -#include +#include "asio/ip/basic_resolver.hpp" +#include "asio/io_context.hpp" #include #include @@ -54,17 +54,17 @@ namespace net { template class endpoints_resolver { private: - std::experimental::net::ip::basic_resolver m_resolver; + asio::ip::basic_resolver m_resolver; public: /** * @brief Construct with an @c io_context. * - * @param ioc @c std::experimental::net::io_context used in the resolver. + * @param ioc @c asio::io_context used in the resolver. * */ - explicit endpoints_resolver(std::experimental::net::io_context& ioc) : m_resolver(ioc) { } + explicit endpoints_resolver(asio::io_context& ioc) : m_resolver(ioc) { } /** * @brief Create a sequence of endpoints and return them in a function object callback. @@ -85,11 +85,10 @@ class endpoints_resolver { * signature of the callback: * * @code - * using namespace std::experimental::net; * // TCP: - * void (std::error_code err, ip::basic_resolver_results); + * void (std::error_code err, asio::ip::basic_resolver_results); * // UDP: - * void (std::error_code err, ip::basic_resolver_results); + * void (std::error_code err, asio::ip::basic_resolver_results); * @endcode * * If an error occurs, the error code is set accordingly. @@ -99,14 +98,12 @@ class endpoints_resolver { void make_endpoints(bool local, std::string_view host_or_intf_name, std::string_view service_or_port, F&& func) { - using namespace std::experimental::net; - // Note - std::move used instead of std::forward since an explicit move or copy // is needed to prevent worry about dangling references if (local) { m_resolver.async_resolve(std::string(host_or_intf_name), std::string(service_or_port), - ip::resolver_base::flags(ip::resolver_base::passive | - ip::resolver_base::address_configured), + asio::ip::resolver_base::flags(asio::ip::resolver_base::passive | + asio::ip::resolver_base::address_configured), std::move(func)); } else { @@ -131,19 +128,18 @@ class endpoints_resolver { * except that a container of endpoints is returned instead of a function object callback * invocation happening at a later point. * - * @return @c std::experimental::net::ip::basic_resolver_results, where Protocol - * is either @c std::experimental::net::ip::tcp or @c std::experimental::net::ip::udp. + * @return @c asio::ip::basic_resolver_results, where Protocol + * is either @c asio::ip::tcp or @c asio::ip::udp. * * @throw @c std::system_error on failure. */ auto make_endpoints(bool local, std::string_view host_or_intf_name, std::string_view service_or_port) { - using namespace std::experimental::net; - if (local) { return m_resolver.resolve(std::string(host_or_intf_name), std::string(service_or_port), - ip::resolver_base::flags(ip::resolver_base::passive | ip::resolver_base::address_configured)); + asio::ip::resolver_base::flags(asio::ip::resolver_base::passive | + asio::ip::resolver_base::address_configured)); } return m_resolver.resolve(std::string(host_or_intf_name), std::string(service_or_port)); } diff --git a/include/net_ip/net_ip.hpp b/include/net_ip/net_ip.hpp index 6e18dde5..77b0d775 100644 --- a/include/net_ip/net_ip.hpp +++ b/include/net_ip/net_ip.hpp @@ -8,7 +8,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -26,9 +26,10 @@ #include -#include -#include -#include +#include "asio/io_context.hpp" +#include "asio/ip/tcp.hpp" +#include "asio/ip/udp.hpp" +#include "asio/post.hpp" #include "net_ip/net_ip_error.hpp" #include "net_ip/net_entity.hpp" @@ -116,7 +117,7 @@ namespace net { class net_ip { private: - std::experimental::net::io_context& m_ioc; + asio::io_context& m_ioc; mutable std::mutex m_mutex; std::vector m_acceptors; @@ -133,7 +134,7 @@ class net_ip { * * @param ioc IO context for asynchronous operations. */ - explicit net_ip(std::experimental::net::io_context& ioc) : + explicit net_ip(asio::io_context& ioc) : m_ioc(ioc), m_acceptors(), m_connectors(), m_udp_entities() { } private: @@ -171,7 +172,7 @@ class net_ip { tcp_acceptor_net_entity make_tcp_acceptor (std::string_view local_port_or_service, std::string_view listen_intf = "", bool reuse_addr = true) { - endpoints_resolver resolver(m_ioc); + endpoints_resolver resolver(m_ioc); auto results = resolver.make_endpoints(true, listen_intf, local_port_or_service); return make_tcp_acceptor(results.cbegin()->endpoint(), reuse_addr); } @@ -183,7 +184,7 @@ class net_ip { * such as directly specifying ipV4 or ipV6 in name resolving, or directly creating the endpoint * without using name resolving. * - * @param endp A @c std::experimental::net::ip::tcp::endpoint that the acceptor uses for the local + * @param endp A @c asio::ip::tcp::endpoint that the acceptor uses for the local * bind (when @c start is called). * * @param reuse_addr If @c true (default), the @c reuse_address socket option is set upon @@ -192,10 +193,10 @@ class net_ip { * @return @c tcp_acceptor_net_entity object. * */ - tcp_acceptor_net_entity make_tcp_acceptor (const std::experimental::net::ip::tcp::endpoint& endp, + tcp_acceptor_net_entity make_tcp_acceptor (const asio::ip::tcp::endpoint& endp, bool reuse_addr = true) { auto p = std::make_shared(m_ioc, endp, reuse_addr); -// std::experimental::net::post(m_ioc.get_executor(), [p, this] () { m_acceptors.push_back(p); } ); +// asio::post(m_ioc.get_executor(), [p, this] () { m_acceptors.push_back(p); } ); lg g(m_mutex); m_acceptors.push_back(p); return tcp_acceptor_net_entity(p); @@ -236,7 +237,7 @@ class net_ip { auto p = std::make_shared(m_ioc, remote_port_or_service, remote_host, reconn_time); -// std::experimental::net::post(m_ioc.get_executor(), [p, this] () { m_connectors.push_back(p); } ); +// asio::post(m_ioc.get_executor(), [p, this] () { m_connectors.push_back(p); } ); lg g(m_mutex); m_connectors.push_back(p); return tcp_connector_net_entity(p); @@ -258,7 +259,7 @@ class net_ip { * * This allows flexibility in creating the remote endpoints for the connector to use. * - * @param beg A begin iterator to a sequence of remote @c std::experimental::net::ip::tcp::endpoint + * @param beg A begin iterator to a sequence of remote @c asio::ip::tcp::endpoint * objects. * * @param end An end iterator to the sequence of endpoints. @@ -274,7 +275,7 @@ class net_ip { std::chrono::milliseconds reconn_time = std::chrono::milliseconds { } ) { auto p = std::make_shared(m_ioc, beg, end, reconn_time); -// std::experimental::net::post(m_ioc.get_executor(), [p, this] () { m_connectors.push_back(p); } ); +// asio::post(m_ioc.get_executor(), [p, this] () { m_connectors.push_back(p); } ); lg g(m_mutex); m_connectors.push_back(p); return tcp_connector_net_entity(p); @@ -283,7 +284,7 @@ class net_ip { /** * @brief Create a TCP connector @c net_entity using a single remote endpoint. * - * @param endp Remote @c std::experimental::net::ip::tcp::endpoint to use for the connect + * @param endp Remote @c asio::ip::tcp::endpoint to use for the connect * attempt. * * @param reconn_time_millis Time period in milliseconds between connect attempts. If 0, no @@ -292,10 +293,10 @@ class net_ip { * @return @c tcp_connector_net_entity object. * */ - tcp_connector_net_entity make_tcp_connector (const std::experimental::net::ip::tcp::endpoint& endp, + tcp_connector_net_entity make_tcp_connector (const asio::ip::tcp::endpoint& endp, std::chrono::milliseconds reconn_time = std::chrono::milliseconds { } ) { - std::vector vec { endp }; + std::vector vec { endp }; return make_tcp_connector(vec.cbegin(), vec.cend(), reconn_time); } @@ -328,7 +329,7 @@ class net_ip { */ udp_net_entity make_udp_unicast (std::string_view local_port_or_service, std::string_view local_intf = "") { - endpoints_resolver resolver(m_ioc); + endpoints_resolver resolver(m_ioc); auto results = resolver.make_endpoints(true, local_intf, local_port_or_service); return make_udp_unicast(results.cbegin()->endpoint()); } @@ -340,15 +341,15 @@ class net_ip { * This @c make method allows flexibility in creating an endpoint for the UDP unicast * @c net_entity to use. * - * @param endp A @c std::experimental::net::ip::udp::endpoint used for the local bind + * @param endp A @c asio::ip::udp::endpoint used for the local bind * (when @c start is called). * * @return @c udp_net_entity object. * */ - udp_net_entity make_udp_unicast (const std::experimental::net::ip::udp::endpoint& endp) { + udp_net_entity make_udp_unicast (const asio::ip::udp::endpoint& endp) { auto p = std::make_shared(m_ioc, endp); - std::experimental::net::post(m_ioc.get_executor(), [p, this] () { m_udp_entities.push_back(p); } ); + asio::post(m_ioc.get_executor(), [p, this] () { m_udp_entities.push_back(p); } ); return udp_net_entity(p); } @@ -361,7 +362,7 @@ class net_ip { * */ udp_net_entity make_udp_sender () { - return make_udp_unicast(std::experimental::net::ip::udp::endpoint()); + return make_udp_unicast(asio::ip::udp::endpoint()); } // TODO: multicast make methods @@ -377,7 +378,7 @@ class net_ip { * */ void remove(tcp_acceptor_net_entity acc) { -// std::experimental::net::post(m_ioc.get_executor(), +// asio::post(m_ioc.get_executor(), // [acc, this] () mutable { // chops::erase_where(m_acceptors, acc.get_shared_ptr()); // } @@ -397,7 +398,7 @@ class net_ip { * */ void remove(tcp_connector_net_entity conn) { -// std::experimental::net::post(m_ioc.get_executor(), +// asio::post(m_ioc.get_executor(), // [conn, this] () mutable { // chops::erase_where(m_connectors, conn.get_shared_ptr()); // } @@ -416,7 +417,7 @@ class net_ip { * */ void remove(udp_net_entity udp_ent) { -// std::experimental::net::post(m_ioc.get_executor(), +// asio::post(m_ioc.get_executor(), // [udp_ent, this] () mutable { // chops::erase_where(m_udp_entities, udp_ent.get_shared_ptr()); // } @@ -433,7 +434,7 @@ class net_ip { * */ void remove_all() { -// std::experimental::net::post(m_ioc.get_executor(), [this] () { +// asio::post(m_ioc.get_executor(), [this] () { // m_udp_entities.clear(); // m_connectors.clear(); // m_acceptors.clear(); @@ -452,7 +453,7 @@ class net_ip { * */ void stop_all() { -// std::experimental::net::post(m_ioc.get_executor(), [this] () { +// asio::post(m_ioc.get_executor(), [this] () { // for (auto i : m_udp_entities) { i->stop(); } // for (auto i : m_connectors) { i->stop(); } // for (auto i : m_acceptors) { i->stop(); } diff --git a/test/include/net_ip/shared_utility_func_test.hpp b/test/include/net_ip/shared_utility_func_test.hpp index e0983027..57aae6d4 100644 --- a/test/include/net_ip/shared_utility_func_test.hpp +++ b/test/include/net_ip/shared_utility_func_test.hpp @@ -7,7 +7,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -20,7 +20,7 @@ #include #include // std::size_t, std::byte -#include +#include "asio/ip/udp.hpp" // udp endpoint #include "net_ip/shared_utility_test.hpp" @@ -69,7 +69,7 @@ inline auto get_udp_io_futures(chops::net::udp_net_entity udp_entity, chops::net inline auto get_udp_io_futures(chops::net::udp_net_entity udp_entity, chops::net::err_wait_q& wq, bool receiving, test_counter& cnt, - const std::experimental::net::ip::udp::endpoint& remote_endp) { + const asio::ip::udp::endpoint& remote_endp) { if (receiving) { return chops::net::make_udp_io_interface_future_pair(udp_entity, diff --git a/test/include/net_ip/shared_utility_test.hpp b/test/include/net_ip/shared_utility_test.hpp index 15bd846a..fabb0277 100644 --- a/test/include/net_ip/shared_utility_test.hpp +++ b/test/include/net_ip/shared_utility_test.hpp @@ -44,8 +44,9 @@ #include #include -#include -#include // ip::udp::endpoint +#include "asio/buffer.hpp" +#include "asio/ip/udp.hpp" // ip::udp::endpoint +#include "asio/ip/address.hpp" // make_address #include @@ -122,7 +123,7 @@ using test_counter = std::atomic_size_t; template struct msg_hdlr { using endp_type = typename IOT::endpoint_type; - using const_buf = std::experimental::net::const_buffer; + using const_buf = asio::const_buffer; bool reply; test_counter& cnt; @@ -166,7 +167,7 @@ inline bool udp_start_io (chops::net::udp_io_interface io, bool reply, test_coun } inline bool udp_start_io (chops::net::udp_io_interface io, bool receiving, test_counter& cnt, - const std::experimental::net::ip::udp::endpoint& remote_endp) { + const asio::ip::udp::endpoint& remote_endp) { if (receiving) { return io.start_io(remote_endp, udp_max_buf_size, udp_msg_hdlr(false, cnt)); } @@ -175,7 +176,7 @@ inline bool udp_start_io (chops::net::udp_io_interface io, bool receiving, test_ struct io_handler_mock { using socket_type = int; - using endpoint_type = std::experimental::net::ip::udp::endpoint; + using endpoint_type = asio::ip::udp::endpoint; socket_type sock = 3; bool started = false; @@ -291,8 +292,8 @@ struct net_entity_mock { inline void io_state_chg_mock(io_interface_mock, std::size_t, bool) { } inline void err_func_mock(io_interface_mock, std::error_code) { } -std::experimental::net::ip::udp::endpoint make_udp_endpoint(const char* addr, int port_num) { - return std::experimental::net::ip::udp::endpoint(std::experimental::net::ip::make_address(addr), +asio::ip::udp::endpoint make_udp_endpoint(const char* addr, int port_num) { + return asio::ip::udp::endpoint(asio::ip::make_address(addr), static_cast(port_num)); } diff --git a/test/net_ip/basic_net_entity_test.cpp b/test/net_ip/basic_net_entity_test.cpp index b88eda9d..5bcc7b85 100644 --- a/test/net_ip/basic_net_entity_test.cpp +++ b/test/net_ip/basic_net_entity_test.cpp @@ -6,7 +6,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,8 +15,6 @@ #include "catch2/catch.hpp" -#include // endpoint declarations - #include // std::shared_ptr #include #include // std::error_code diff --git a/test/net_ip/component/simple_variable_len_msg_frame_test.cpp b/test/net_ip/component/simple_variable_len_msg_frame_test.cpp index d69a90cf..fde67550 100644 --- a/test/net_ip/component/simple_variable_len_msg_frame_test.cpp +++ b/test/net_ip/component/simple_variable_len_msg_frame_test.cpp @@ -15,15 +15,13 @@ #include "catch2/catch.hpp" -#include +#include "asio/buffer.hpp" #include // std::size_t, std::byte #include "utility/make_byte_array.hpp" #include "net_ip/component/simple_variable_len_msg_frame.hpp" -using namespace std::experimental::net; - std::size_t decoder_func (const std::byte* buf, std::size_t sz) { REQUIRE (sz == 1); return static_cast(*buf); @@ -42,13 +40,13 @@ SCENARIO ( "Simple variable len message frame test", WHEN ("it is called multiple times") { THEN ("the return value toggles between the decoder supplied number and zero") { std::size_t idx = 0; - mutable_buffer mbuf; + asio::mutable_buffer mbuf; while (idx < msgs.size()) { - mbuf = mutable_buffer(msgs.data() + idx, 1); + mbuf = asio::mutable_buffer(msgs.data() + idx, 1); auto ret = mf(mbuf); INFO("Return from msg frame: " << ret); idx += ret; - mbuf = mutable_buffer(msgs.data() + idx, ret); + mbuf = asio::mutable_buffer(msgs.data() + idx, ret); ret = mf(mbuf); REQUIRE (ret == 0); idx += 1; diff --git a/test/net_ip/detail/io_common_test.cpp b/test/net_ip/detail/io_common_test.cpp index 695afae3..b65e7a35 100644 --- a/test/net_ip/detail/io_common_test.cpp +++ b/test/net_ip/detail/io_common_test.cpp @@ -6,7 +6,7 @@ * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,8 +15,7 @@ #include "catch2/catch.hpp" -#include // endpoint declarations -#include +#include "asio/io_context.hpp" #include // std::shared_ptr #include // std::error_code @@ -33,7 +32,6 @@ template void io_common_test(chops::const_shared_buffer buf, int num_bufs, typename IOT::endpoint_type endp) { - using namespace std::experimental::net; using namespace std::placeholders; REQUIRE (num_bufs > 1); @@ -154,8 +152,6 @@ struct io_mock { }; SCENARIO ( "Io common test", "[io_common]" ) { - using namespace std::experimental::net; - auto ba = chops::make_byte_array(0x20, 0x21, 0x22, 0x23, 0x24); chops::mutable_shared_buffer mb(ba.data(), ba.size()); io_common_test(chops::const_shared_buffer(std::move(mb)), 20, 42.0); diff --git a/test/net_ip/detail/output_queue_test.cpp b/test/net_ip/detail/output_queue_test.cpp index a4b5b2ff..76ea884d 100644 --- a/test/net_ip/detail/output_queue_test.cpp +++ b/test/net_ip/detail/output_queue_test.cpp @@ -17,7 +17,8 @@ #include // std::move -#include // endpoint declarations +#include // endpoint declarations +#include // endpoint declarations #include "net_ip/detail/output_queue.hpp" @@ -85,23 +86,21 @@ void get_next_element_test(chops::const_shared_buffer buf, int num_bufs, SCENARIO ( "Output_queue test, udp endpoint", "[output_queue] [udp]" ) { - using namespace std::experimental::net; auto ba = chops::make_byte_array(0x20, 0x21, 0x22, 0x23, 0x24); chops::mutable_shared_buffer mb(ba.data(), ba.size()); - add_element_test(chops::const_shared_buffer(std::move(mb)), 10); - get_next_element_test(chops::const_shared_buffer(std::move(mb)), 20, - ip::udp::endpoint(ip::udp::v4(), 1234)); + add_element_test(chops::const_shared_buffer(std::move(mb)), 10); + get_next_element_test(chops::const_shared_buffer(std::move(mb)), 20, + asio::ip::udp::endpoint(asio::ip::udp::v4(), 1234)); } SCENARIO ( "Output_queue test, tcp endpoint", "[output_queue] [tcp]" ) { - using namespace std::experimental::net; auto ba = chops::make_byte_array(0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46); chops::mutable_shared_buffer mb(ba.data(), ba.size()); - add_element_test(chops::const_shared_buffer(std::move(mb)), 30); - get_next_element_test(chops::const_shared_buffer(std::move(mb)), 40, - ip::tcp::endpoint(ip::tcp::v6(), 9876)); + add_element_test(chops::const_shared_buffer(std::move(mb)), 30); + get_next_element_test(chops::const_shared_buffer(std::move(mb)), 40, + asio::ip::tcp::endpoint(asio::ip::tcp::v6(), 9876)); } diff --git a/test/net_ip/detail/tcp_acceptor_test.cpp b/test/net_ip/detail/tcp_acceptor_test.cpp index 5f3c2110..d28a0e74 100644 --- a/test/net_ip/detail/tcp_acceptor_test.cpp +++ b/test/net_ip/detail/tcp_acceptor_test.cpp @@ -11,7 +11,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -20,10 +20,12 @@ #include "catch2/catch.hpp" -#include -#include -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/write.hpp" +#include "asio/read.hpp" +#include "asio/buffer.hpp" +#include "asio/io_context.hpp" +#include "asio/connect.hpp" #include // std::error_code #include // std::size_t @@ -48,7 +50,6 @@ // #include -using namespace std::experimental::net; using namespace chops::test; const char* test_port = "30434"; @@ -58,32 +59,32 @@ constexpr int NumMsgs = 50; // Catch test framework not thread-safe, all REQUIRE clauses must be in single thread -std::size_t connector_func (const vec_buf& in_msg_vec, io_context& ioc, +std::size_t connector_func (const vec_buf& in_msg_vec, asio::io_context& ioc, bool read_reply, int interval, chops::const_shared_buffer empty_msg) { - ip::tcp::socket sock(ioc); - auto endp_seq = chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); - ip::tcp::endpoint endp = connect(sock, endp_seq); + asio::ip::tcp::socket sock(ioc); + auto endp_seq = chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); + asio::ip::tcp::endpoint endp = asio::connect(sock, endp_seq); std::size_t cnt = 0; chops::mutable_shared_buffer return_msg { }; for (auto buf : in_msg_vec) { - write(sock, const_buffer(buf.data(), buf.size())); + asio::write(sock, asio::const_buffer(buf.data(), buf.size())); if (read_reply) { return_msg.resize(buf.size()); - read(sock, mutable_buffer(return_msg.data(), return_msg.size())); + asio::read(sock, asio::mutable_buffer(return_msg.data(), return_msg.size())); ++cnt; } std::this_thread::sleep_for(std::chrono::milliseconds(interval)); } - write(sock, const_buffer(empty_msg.data(), empty_msg.size())); + asio::write(sock, asio::const_buffer(empty_msg.data(), empty_msg.size())); char c; std::error_code ec; - auto sz = read(sock, mutable_buffer(&c, 1), ec); // block on read until connection is closed + auto sz = asio::read(sock, asio::mutable_buffer(&c, 1), ec); // block on read until connection is closed return cnt; } -std::size_t start_connector_funcs (const vec_buf& in_msg_vec, io_context& ioc, +std::size_t start_connector_funcs (const vec_buf& in_msg_vec, asio::io_context& ioc, bool reply, int interval, int num_conns, std::string_view delim, chops::const_shared_buffer empty_msg) { @@ -116,7 +117,7 @@ void acceptor_test (const vec_buf& in_msg_vec, bool reply, int interval, int num THEN ("the futures provide synchronization and data returns") { auto endp_seq = - chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); + chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); auto acc_ptr = std::make_shared(ioc, *(endp_seq.cbegin()), true); diff --git a/test/net_ip/detail/tcp_connector_test.cpp b/test/net_ip/detail/tcp_connector_test.cpp index e06571ef..3bd66624 100644 --- a/test/net_ip/detail/tcp_connector_test.cpp +++ b/test/net_ip/detail/tcp_connector_test.cpp @@ -18,10 +18,9 @@ #include "catch2/catch.hpp" -#include -#include -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/buffer.hpp" +#include "asio/io_context.hpp" #include // std::error_code #include // std::size_t @@ -53,7 +52,6 @@ #include // std::cerr for error sink -using namespace std::experimental::net; using namespace chops::test; const char* test_port = "30777"; @@ -63,7 +61,7 @@ constexpr int ReconnTime = 100; // Catch test framework not thread-safe, all REQUIRE clauses must be in single thread -void start_connectors(const vec_buf& in_msg_vec, io_context& ioc, +void start_connectors(const vec_buf& in_msg_vec, asio::io_context& ioc, int interval, int num_conns, std::string_view delim, chops::const_shared_buffer empty_msg, test_counter& conn_cnt, chops::net::err_wait_q& err_wq) { @@ -122,7 +120,7 @@ void acc_conn_test (const vec_buf& in_msg_vec, bool reply, int interval, int num THEN ("the futures provide synchronization and data returns") { auto endp_seq = - chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); + chops::net::endpoints_resolver(ioc).make_endpoints(true, test_host, test_port); auto acc_ptr = std::make_shared(ioc, *(endp_seq.cbegin()), true); diff --git a/test/net_ip/detail/tcp_io_test.cpp b/test/net_ip/detail/tcp_io_test.cpp index 0d753eea..03bdfeae 100644 --- a/test/net_ip/detail/tcp_io_test.cpp +++ b/test/net_ip/detail/tcp_io_test.cpp @@ -15,9 +15,9 @@ #include "catch2/catch.hpp" -#include -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/connect.hpp" +#include "asio/io_context.hpp" #include // std::error_code #include // std::size_t @@ -39,7 +39,6 @@ // #include -using namespace std::experimental::net; using namespace chops::test; // using notifier_cb = @@ -65,13 +64,13 @@ struct notify_me { } }; -std::size_t connector_func (const vec_buf& in_msg_vec, io_context& ioc, +std::size_t connector_func (const vec_buf& in_msg_vec, asio::io_context& ioc, int interval, std::string_view delim, chops::const_shared_buffer empty_msg) { auto endps = - chops::net::endpoints_resolver(ioc).make_endpoints(true, test_addr, test_port); - ip::tcp::socket sock(ioc); - connect(sock, endps); + chops::net::endpoints_resolver(ioc).make_endpoints(true, test_addr, test_port); + asio::ip::tcp::socket sock(ioc); + asio::connect(sock, endps); notify_prom_type notify_prom; auto notify_fut = notify_prom.get_future(); @@ -109,8 +108,8 @@ void acc_conn_test (const vec_buf& in_msg_vec, bool reply, int interval, std::st THEN ("the futures provide synchronization and data returns") { auto endps = - chops::net::endpoints_resolver(ioc).make_endpoints(true, test_addr, test_port); - ip::tcp::acceptor acc(ioc, *(endps.cbegin())); + chops::net::endpoints_resolver(ioc).make_endpoints(true, test_addr, test_port); + asio::ip::tcp::acceptor acc(ioc, *(endps.cbegin())); INFO ("Creating connector asynchronously, msg interval: " << interval); diff --git a/test/net_ip/detail/udp_entity_io_test.cpp b/test/net_ip/detail/udp_entity_io_test.cpp index 877abb17..06d2f969 100644 --- a/test/net_ip/detail/udp_entity_io_test.cpp +++ b/test/net_ip/detail/udp_entity_io_test.cpp @@ -11,7 +11,7 @@ * * @author Cliff Green * - * Copyright (c) 2018 by Cliff Green + * Copyright (c) 2018-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -20,9 +20,8 @@ #include "catch2/catch.hpp" -#include -#include -#include +#include "asio/ip/udp.hpp" +#include "asio/io_context.hpp" #include // std::error_code #include // std::size_t @@ -52,7 +51,7 @@ #include // std::err for error sink -using namespace std::experimental::net; +using namespace asio; using namespace chops::test; // using notifier_cb = diff --git a/test/net_ip/endpoints_resolver_test.cpp b/test/net_ip/endpoints_resolver_test.cpp index 5ada7680..f5ab977e 100644 --- a/test/net_ip/endpoints_resolver_test.cpp +++ b/test/net_ip/endpoints_resolver_test.cpp @@ -15,8 +15,9 @@ #include "catch2/catch.hpp" -#include -#include +#include "asio/ip/tcp.hpp" +#include "asio/ip/udp.hpp" +#include "asio/ip/basic_resolver.hpp" #include // std::error_code #include // std::pair @@ -28,12 +29,10 @@ #include "net_ip/endpoints_resolver.hpp" #include "net_ip/component/worker.hpp" -using namespace std::experimental::net; - template void make_endpoints_test (bool local, std::string_view host, std::string_view port, bool expected_good) { - using results_t = ip::basic_resolver_results; + using results_t = asio::ip::basic_resolver_results; using prom_ret = std::pair; using namespace std::literals::chrono_literals; @@ -97,49 +96,49 @@ std::cerr << "-- Endpoint: " << i.endpoint() << std::endl; SCENARIO ( "Make endpoints remote test, TCP 1", "[make_endpoints] [tcp]" ) { - make_endpoints_test (false, "www.cnn.com", "80", true); + make_endpoints_test (false, "www.cnn.com", "80", true); } SCENARIO ( "Make endpoints remote test, TCP 2", "[make_endpoints] [tcp]" ) { - make_endpoints_test (false, "www.seattletimes.com", "80", true); + make_endpoints_test (false, "www.seattletimes.com", "80", true); } SCENARIO ( "Make endpoints local test, TCP 3", "[make_endpoints] [tcp]" ) { - make_endpoints_test (true, "", "23000", true); + make_endpoints_test (true, "", "23000", true); } SCENARIO ( "Make endpoints remote test, UDP 1", "[make_endpoints] [udp]" ) { - make_endpoints_test (false, "www.cnn.com", "80", true); + make_endpoints_test (false, "www.cnn.com", "80", true); } SCENARIO ( "Make endpoints remote test, UDP 2", "[make_endpoints] [udp]" ) { - make_endpoints_test (false, "www.seattletimes.com", "80", true); + make_endpoints_test (false, "www.seattletimes.com", "80", true); } SCENARIO ( "Make endpoints local test, UDP 3", "[make_endpoints] [udp]" ) { - make_endpoints_test (true, "", "23000", true); + make_endpoints_test (true, "", "23000", true); } /* SCENARIO ( "Make endpoints remote test, TCP invalid", "[tcp_make_endpoints_invalid]" ) { - make_endpoints_test (false, "frobozz.blaaaarg", "32555", false); + make_endpoints_test (false, "frobozz.blaaaarg", "32555", false); } */ diff --git a/test/net_ip/net_ip_test.cpp b/test/net_ip/net_ip_test.cpp index 5e8544e2..a3fe3fce 100644 --- a/test/net_ip/net_ip_test.cpp +++ b/test/net_ip/net_ip_test.cpp @@ -15,11 +15,6 @@ #include "catch2/catch.hpp" -#include -#include -#include -#include - #include // std::error_code #include // std::size_t #include // std::make_shared @@ -47,7 +42,6 @@ #include // std::cerr for error sink -using namespace std::experimental::net; using namespace chops::test; const char* tcp_test_port = "30465"; diff --git a/test/net_ip/shared_utility_func_test.cpp b/test/net_ip/shared_utility_func_test.cpp index 1011ca54..97df48eb 100644 --- a/test/net_ip/shared_utility_func_test.cpp +++ b/test/net_ip/shared_utility_func_test.cpp @@ -18,7 +18,7 @@ #include -#include +#include "asio/ip/udp.hpp" #include "net_ip/shared_utility_func_test.hpp" @@ -30,7 +30,7 @@ SCENARIO ( "Shared Net IP test utility, get_tcp_io_futures", "[shared_utility] [tcp_io_futures]" ) { using namespace chops::test; - chops::net::tcp_err_wait_q wq; + chops::net::err_wait_q wq; test_counter cnt; auto futs = get_tcp_io_futures(chops::net::tcp_connector_net_entity(), wq, true, std::string_view(), cnt); @@ -40,19 +40,19 @@ SCENARIO ( "Shared Net IP test utility, get_udp_io_futures", "[shared_utility] [udp_io_futures]" ) { using namespace chops::test; - chops::net::udp_err_wait_q wq; + chops::net::err_wait_q wq; test_counter cnt; auto futs1 = get_udp_io_futures(chops::net::udp_net_entity(), wq, true, cnt); auto futs2 = get_udp_io_futures(chops::net::udp_net_entity(), wq, - true, cnt, std::experimental::net::ip::udp::endpoint()); + true, cnt, asio::ip::udp::endpoint()); } SCENARIO ( "Shared Net IP test utility, start TCP acceptor", "[shared_utility] [start_tcp_acceptor]" ) { using namespace chops::test; - chops::net::tcp_err_wait_q wq; + chops::net::err_wait_q wq; test_counter cnt; start_tcp_acceptor(chops::net::tcp_acceptor_net_entity(), wq, false, std::string_view(), cnt); diff --git a/test/net_ip/shared_utility_test.cpp b/test/net_ip/shared_utility_test.cpp index e4eb8872..3a81f40e 100644 --- a/test/net_ip/shared_utility_test.cpp +++ b/test/net_ip/shared_utility_test.cpp @@ -29,8 +29,8 @@ #include // std::shared_ptr, std::make_shared #include -#include -#include +#include "asio/ip/udp.hpp" +#include "asio/buffer.hpp" #include "utility/make_byte_array.hpp" #include "utility/shared_buffer.hpp" @@ -124,25 +124,24 @@ void make_msg_vec_test(F&& f) { template std::size_t msg_hdlr_stress_test(F&& f, std::string_view pre, char body_char, int num_msgs) { using namespace chops::test; - using namespace std::experimental::net; auto msgs = make_msg_vec(f, pre, body_char, num_msgs); auto empty = make_empty_body_msg(f); auto iohp = std::make_shared(); - ip::udp::endpoint endp { }; + asio::ip::udp::endpoint endp { }; test_counter cnt(0); msg_hdlr mh(false, cnt); int m = 0; for (auto i : msgs) { - auto ret = mh(const_buffer(i.data(), i.size()), io_interface_mock(iohp), endp); + auto ret = mh(asio::const_buffer(i.data(), i.size()), io_interface_mock(iohp), endp); if (++m % 1000 == 0) { REQUIRE(ret); } } - REQUIRE_FALSE(mh(const_buffer(empty.data(), empty.size()), io_interface_mock(iohp), endp)); + REQUIRE_FALSE(mh(asio::const_buffer(empty.data(), empty.size()), io_interface_mock(iohp), endp)); return cnt.load(); @@ -178,7 +177,6 @@ SCENARIO ( "Shared Net IP test utility, make msg vec", SCENARIO ( "Shared Net IP test utility, decode variable len msg header", "[shared_utility] [decode_variable_len_msg]" ) { using namespace chops::test; - using namespace std::experimental::net; auto ba = chops::make_byte_array(0x02, 0x01); // 513 in big endian @@ -189,7 +187,7 @@ SCENARIO ( "Shared Net IP test utility, decode variable len msg header", } } AND_WHEN ("a simple variable len msg frame is constructed") { - mutable_buffer buf(ba.data(), ba.size()); + asio::mutable_buffer buf(ba.data(), ba.size()); auto mf = chops::net::make_simple_variable_len_msg_frame(decode_variable_len_msg_hdr); THEN ("the returned length toggles between the decoded length and zero") { REQUIRE(mf(buf) == 513); @@ -204,11 +202,10 @@ SCENARIO ( "Shared Net IP test utility, decode variable len msg header", SCENARIO ( "Shared Net IP test utility, msg hdlr", "[shared_utility] [msg_hdlr]" ) { using namespace chops::test; - using namespace std::experimental::net; auto iohp = std::make_shared(); REQUIRE_FALSE(iohp->send_called); - ip::udp::endpoint endp { }; + asio::ip::udp::endpoint endp { }; auto msg = make_variable_len_msg(make_body_buf("Bah, humbug!", 'T', 4)); auto empty = make_empty_variable_len_msg(); @@ -219,9 +216,9 @@ SCENARIO ( "Shared Net IP test utility, msg hdlr", test_counter cnt(0); msg_hdlr mh(true, cnt); THEN ("the shutdown message is handled correctly and count is correct") { - REQUIRE(mh(const_buffer(msg.data(), msg.size()), io_interface_mock(iohp), endp)); + REQUIRE(mh(asio::const_buffer(msg.data(), msg.size()), io_interface_mock(iohp), endp)); REQUIRE(iohp->send_called); - REQUIRE_FALSE(mh(const_buffer(empty.data(), empty.size()), + REQUIRE_FALSE(mh(asio::const_buffer(empty.data(), empty.size()), io_interface_mock(iohp), endp)); REQUIRE(cnt == 1); } @@ -230,8 +227,8 @@ SCENARIO ( "Shared Net IP test utility, msg hdlr", test_counter cnt(0); msg_hdlr mh(false, cnt); THEN ("the shutdown message is handled correctly and count is correct") { - REQUIRE(mh(const_buffer(msg.data(), msg.size()), io_interface_mock(iohp), endp)); - REQUIRE_FALSE(mh(const_buffer(empty.data(), empty.size()), + REQUIRE(mh(asio::const_buffer(msg.data(), msg.size()), io_interface_mock(iohp), endp)); + REQUIRE_FALSE(mh(asio::const_buffer(empty.data(), empty.size()), io_interface_mock(iohp), endp)); REQUIRE(cnt == 1); } @@ -265,7 +262,6 @@ SCENARIO ( "Shared Net IP test utility, msg hdlr async stress test", SCENARIO ( "Shared Net IP test utility, io_handler_mock test", "[shared_utility] [io_handler_mock]" ) { using namespace chops::test; - using namespace std::experimental::net; io_handler_mock io_mock { }; @@ -323,7 +319,7 @@ SCENARIO ( "Shared Net IP test utility, io_handler_mock test", } AND_WHEN ("fourth start_io overload is called") { THEN ("the related flag is true") { - io_mock.start_io(ip::udp::endpoint(), 0, [] { }); + io_mock.start_io(asio::ip::udp::endpoint(), 0, [] { }); REQUIRE (io_mock.rd_endp_sio_called); } } @@ -335,7 +331,7 @@ SCENARIO ( "Shared Net IP test utility, io_handler_mock test", } AND_WHEN ("sixth start_io overload is called") { THEN ("the related flag is true") { - io_mock.start_io(ip::udp::endpoint()); + io_mock.start_io(asio::ip::udp::endpoint()); REQUIRE (io_mock.send_endp_sio_called); } } From 0adc6efa25d093ff391dbd98971a8a77c019483d Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Mon, 11 Mar 2019 17:12:02 -0700 Subject: [PATCH 11/16] Tweaking test execution order. --- test/CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4a5466b..84b00485 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,24 +16,24 @@ set ( tester_suffix "_runner" ) set ( main_test_lib_name "main_test_lib" ) set ( test_sources - "${test_source_dir}/net_ip/basic_io_interface_test.cpp" - "${test_source_dir}/net_ip/basic_net_entity_test.cpp" - "${test_source_dir}/net_ip/endpoints_resolver_test.cpp" - "${test_source_dir}/net_ip/net_ip_error_test.cpp" - "${test_source_dir}/net_ip/net_ip_test.cpp" - "${test_source_dir}/net_ip/shared_utility_func_test.cpp" - "${test_source_dir}/net_ip/shared_utility_test.cpp" - "${test_source_dir}/net_ip/component/error_delivery_test.cpp" - "${test_source_dir}/net_ip/component/io_interface_delivery_test.cpp" - "${test_source_dir}/net_ip/component/send_to_all_test.cpp" - "${test_source_dir}/net_ip/component/simple_variable_len_msg_frame_test.cpp" "${test_source_dir}/net_ip/detail/io_common_test.cpp" "${test_source_dir}/net_ip/detail/net_entity_common_test.cpp" "${test_source_dir}/net_ip/detail/output_queue_test.cpp" "${test_source_dir}/net_ip/detail/tcp_acceptor_test.cpp" "${test_source_dir}/net_ip/detail/tcp_connector_test.cpp" "${test_source_dir}/net_ip/detail/tcp_io_test.cpp" - "${test_source_dir}/net_ip/detail/udp_entity_io_test.cpp" ) + "${test_source_dir}/net_ip/detail/udp_entity_io_test.cpp" + "${test_source_dir}/net_ip/component/error_delivery_test.cpp" + "${test_source_dir}/net_ip/component/io_interface_delivery_test.cpp" + "${test_source_dir}/net_ip/component/send_to_all_test.cpp" + "${test_source_dir}/net_ip/component/simple_variable_len_msg_frame_test.cpp" + "${test_source_dir}/net_ip/basic_io_interface_test.cpp" + "${test_source_dir}/net_ip/basic_net_entity_test.cpp" + "${test_source_dir}/net_ip/endpoints_resolver_test.cpp" + "${test_source_dir}/net_ip/net_ip_error_test.cpp" + "${test_source_dir}/net_ip/shared_utility_test.cpp" + "${test_source_dir}/net_ip/shared_utility_func_test.cpp" + "${test_source_dir}/net_ip/net_ip_test.cpp" ) set ( OPTIONS "" ) set ( DEFINITIONS "" ) From ee78ece9b0e696425bf38f21694653da63abf4de Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Tue, 12 Mar 2019 13:28:09 -0700 Subject: [PATCH 12/16] Doc updates. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14f223e9..703e33cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Chops Net IP - Connective Handcrafted Openwork Software for Asynchronous IP Networking -Chops Net IP is a C++ library that makes asynchronous networking programming fun. Or at least if not fun, it makes network programming easier and safer without significantly sacrificing performance. It is built on top of the Asio asynchronous networking library and handles Internet Protocol (IP) communications including TCP, UDP, and UDP multicast. It is written using modern C++ design idioms and the latest (2017) C++ standard. +Chops Net IP is a C++ library that makes asynchronous networking programming fun. Or at least if not fun, it makes network programming Asio, easier and safer, without significantly sacrificing performance. It is layered on top of the Asio asynchronous networking library, which is not an easy library to use correctly. It handles Internet Protocol (IP) communications including TCP, UDP, and UDP multicast. It is written using modern C++ design idioms and the latest (2017) C++ standard. + +Chops Net IP is not like any other high-level, general purpose C++ socket library. + +# License This project is distributed under the [Boost Software License](LICENSE.txt). From 161ccead95f2fad1a731bc3341e82ab2a65e446f Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Thu, 14 Mar 2019 20:03:25 -0700 Subject: [PATCH 13/16] Using std::string_view in async_resolve calls, changed from std::string (which was the old interface). --- include/net_ip/endpoints_resolver.hpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/include/net_ip/endpoints_resolver.hpp b/include/net_ip/endpoints_resolver.hpp index 51d90adb..0717a9c1 100644 --- a/include/net_ip/endpoints_resolver.hpp +++ b/include/net_ip/endpoints_resolver.hpp @@ -2,15 +2,11 @@ * * @ingroup net_ip_module * - * @brief Class to convert network host names and ports into C++ Networking TS - * endpoint objects. - * - * @note Chris' Networking TS is not yet recognizing @c string_view on g++ 7.2, so a - * @c string is constructed for the @c string_view parms. + * @brief Class to convert network host names and ports into Asio endpoint objects. * * @author Cliff Green * - * Copyright (c) 2017-2018 by Cliff Green + * Copyright (c) 2017-2019 by Cliff Green * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -32,10 +28,10 @@ namespace net { /** * @brief Convenience class for resolving names to endpoints suitable for use - * within the Chops Net IP library (or with the C++ Networking TS). + * within the Chops Net IP library (or with the Asio API). * * This class does not add much functionality above what is already present in the - * Networking TS, but does automate the flags for local resolves. + * Asio library, but does automate the flags for local resolves. * * Many times only one endpoint is needed, for example a TCP acceptor local endpoint or a * UDP local endpoint. In this case the first entry of an endpoint sequence can @@ -101,13 +97,13 @@ class endpoints_resolver { // Note - std::move used instead of std::forward since an explicit move or copy // is needed to prevent worry about dangling references if (local) { - m_resolver.async_resolve(std::string(host_or_intf_name), std::string(service_or_port), + m_resolver.async_resolve(host_or_intf_name, service_or_port, asio::ip::resolver_base::flags(asio::ip::resolver_base::passive | asio::ip::resolver_base::address_configured), std::move(func)); } else { - m_resolver.async_resolve(std::string(host_or_intf_name), std::string(service_or_port), + m_resolver.async_resolve(host_or_intf_name, service_or_port, std::move(func)); } return; @@ -137,7 +133,7 @@ class endpoints_resolver { auto make_endpoints(bool local, std::string_view host_or_intf_name, std::string_view service_or_port) { if (local) { - return m_resolver.resolve(std::string(host_or_intf_name), std::string(service_or_port), + return m_resolver.resolve(host_or_intf_name, service_or_port, asio::ip::resolver_base::flags(asio::ip::resolver_base::passive | asio::ip::resolver_base::address_configured)); } From 9ca1c0fd86e4c7a7f171dd8794770e0985b51e48 Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Thu, 14 Mar 2019 20:03:50 -0700 Subject: [PATCH 14/16] Changed comments that referenced Networking TS to Asio. --- doc/faq.md | 8 ++++---- include/net_ip/component/worker.hpp | 2 +- include/net_ip/net_ip.hpp | 2 +- test/net_ip/detail/tcp_acceptor_test.cpp | 2 +- test/net_ip/detail/tcp_connector_test.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/faq.md b/doc/faq.md index 47555f09..5c569d79 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -5,19 +5,19 @@ - Why not use one of the many other networking or socket libraries? - Chops Net IP scales very well, using system resources efficiently. It performs well. It is portable across many compilers and platforms. It defines application customization points that few other libraries have. The abstractions it provides are flexible and useful in many domains. It provides TCP, UDP, and UDP multicasting functionality, abstracting away many of the differences between those protocols. - When should I not use Chops Net IP? - - When you need abstractions for a specific complex and widely used domain. For example, serious web server applications should consider using Boost Beast (written by Vinnie Falco) or one of the many web frameworks that are available. If absolute raw performance is needed, writing directly to the C++ Networking TS (or using a similar library) would be better, giving up the convenience and flexibility that Chops Net IP provides. + - When you need abstractions for a specific complex and widely used domain. For example, serious web server applications should consider using Boost Beast (written by Vinnie Falco) or one of the many web frameworks that are available. If absolute raw performance is needed, writing directly to the Asio API (or similar) would be better, giving up the convenience and flexibility that Chops Net IP provides. - Is Chops Net IP a framework? - No. It is a general purpose library. There are no specific network protocols required by the library and no wire protocols added by the library. It can communicate with any TCP or UDP application. Obviously the wire protocols and communication semantics need to be appropriately implemented by the application using the Chops Net IP library. - Wny is a queue required for outgoing data? - - Applications may send data faster than it can be consumed at the remote end (or passed through the local network stack). Queueing the outgoing data allows timely processing if this situation occurs. One design possibility for the library is to push the responsibility of sending the next chunk of data back to the application, but this requires a non-trivial API interaction between the library and the application. "Fire and forget" makes for an easy application API at the cost of the outgoing queue overhead. + - Applications may send data faster than it can be consumed at the remote end (or passed through the local network stack). Queueing the outgoing data allows timely processing if this situation occurs. There is an API design choice for outgoing data: 1) notify the application when outgoing data can be sent 2) queue the data when needed and let the Chops Net IP library manage the outgoing data notifications. The Chops Net IP API philosophy is "fire and forget" (i.e. all calls immediately return to the application), which leads to an outgoing queue. However, applications may have different memory constraints, and the Chops Net IP library allows different containers to be used (at compile) time for the outgoing queue. For example, a fixed size ring buffer or circular queue can be used (as long as the queue requirements are met). - What if the outgoing data queue becomes large? - This is an indication that the remote end is not processing data fast enough (or that data is being produced too fast). The application can query outgoing queue stats to determine if this scenario is occurring. - Why not provide a configuration API for a table-driven network application? - There are many different formats and types of configurations, including dynamically generated configurations. Configuration should be a separate concern from the Chops Net IP library. Configuration parsing for common formats (e.g. JSON) may be added to the `component` directory (non-dependent convenience classes and functions) in the future or provided in separate repositories. - Are there logging or tracing facilities in Chops Net IP? - No. There is not a logging library or design that is generic enough to work in every environment. Even general purpose logging libraries have a set of tradeoffs that are not acceptable for Chops Net IP. Instead, the approach taken by Chops Net IP is to provide customization points for every meaningful step in the networking processing flow. This allows the application complete flexibility in using whatever logging facilities it wishes. -- Is Chops Net IP a complete wrapper over the C++ Networking TS? - - No. There are access points that expose various Networking TS facilities, and Networking TS `endpoints` are used in the Chops Net IP API. In particular, Chops Net IP provides an interface to access the underlying Networking TS socket and the application can directly set (or query) socket options (versus wrapping and exactly duplicating the functionality). +- Is Chops Net IP a complete wrapper over the Asio API? + - No. There are access points that expose various Asio facilities, and Asio `endpoints` are used in the Chops Net IP API. In particular, Chops Net IP provides an interface to access the underlying Asio socket and the application can directly set (or query) socket options (versus wrapping and exactly duplicating the functionality). - What are some of the subtle design challenges in the implementation? - Passing application supplied function objects through the library layers is central to the design. Since these are passed across thread boundaries at certain points, knowing when to call `std::move` versus `std::forward` is crucial (and has been the source of more than one bug). - The shutdown notification logic is tricky and hard to get correct, specially between the TCP connection object and the TCP acceptor and TCP connector objects. diff --git a/include/net_ip/component/worker.hpp b/include/net_ip/component/worker.hpp index 1cbc663b..9800f5f9 100644 --- a/include/net_ip/component/worker.hpp +++ b/include/net_ip/component/worker.hpp @@ -33,7 +33,7 @@ namespace net { /** * @brief Convenience class that combines an executor work guard and a thread, - * invoking asynchronous operations as per the C++ Networking TS. + * invoking asynchronous operations as per the Asio documentation. * * @note This class is not a necessary dependency of the @c net_ip library, but * is provided for convenience in many use cases. diff --git a/include/net_ip/net_ip.hpp b/include/net_ip/net_ip.hpp index 77b0d775..1b4c1b65 100644 --- a/include/net_ip/net_ip.hpp +++ b/include/net_ip/net_ip.hpp @@ -91,7 +91,7 @@ namespace net { * There are no executor operations available through the @c net_ip class. In * other words, no event loop or @c run methods are available. Instead, the * @c net_ip class takes an @c io_context as a constructor parameter and - * application code will use the Networking TS executor methods for invoking + * application code will use the Asio executor methods for invoking * the underlying asynchronous operations. * * For convenience, a class named @c worker in the @c component directory combines diff --git a/test/net_ip/detail/tcp_acceptor_test.cpp b/test/net_ip/detail/tcp_acceptor_test.cpp index d28a0e74..df70686b 100644 --- a/test/net_ip/detail/tcp_acceptor_test.cpp +++ b/test/net_ip/detail/tcp_acceptor_test.cpp @@ -7,7 +7,7 @@ * This test is similar to the tcp_io_test code, with a little bit less * internal plumbing, and allowing multiple connector threads to be started. * The TCP acceptor is the Chops Net IP class, but the connector threads are - * using blocking Networking TS connects and io. + * using blocking Asio connects and io. * * @author Cliff Green * diff --git a/test/net_ip/detail/tcp_connector_test.cpp b/test/net_ip/detail/tcp_connector_test.cpp index 3bd66624..7f679b37 100644 --- a/test/net_ip/detail/tcp_connector_test.cpp +++ b/test/net_ip/detail/tcp_connector_test.cpp @@ -5,7 +5,7 @@ * @brief Test scenarios for @c tcp_connector detail class. * * This test is similar to the tcp_acceptor_test code, except the Chops Net IP - * tcp_connector class instead of Networking TS blocking io calls. + * tcp_connector class instead of Asio blocking io calls. * * @author Cliff Green * From 867a0168e0e340facbf3349c64050ea53384d18f Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Sat, 23 Mar 2019 18:15:30 -0700 Subject: [PATCH 15/16] Updating doc. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 703e33cd..8b39cf53 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ See [References](doc/references.md) for additional details on the above librarie Chops Net IP has been compiled and tests run on: -- g++ 7.2, Linux (Ubuntu 17.10, Linux kernel 4.13) +- g++ 7.2, g++ 7.3, Linux (Ubuntu 17.10 - kernel 4.13, Ubuntu 18.04 - kernel 4.15) - (TBD, will include at least clang on linux and vc++ on Windows) # Installation From 0bc740fcffb3e4bcba2c2a15df35c3c5eaf8ab31 Mon Sep 17 00:00:00 2001 From: Cliff Green Date: Sat, 23 Mar 2019 18:23:25 -0700 Subject: [PATCH 16/16] Updating CMake files for chops-net-ip repo. --- example/CMakeLists.txt | 84 ++++++++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 example/CMakeLists.txt diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 00000000..ef37c451 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,84 @@ +# Copyright 2019 by Cliff Green +# +# https://github.com/connectivecpp/chops-net-ip +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +cmake_minimum_required ( VERSION 3.8 ) + +project ( chops-net-ip-example VERSION 1.0 LANGUAGES CXX ) + +set ( example_source_dir "${CMAKE_SOURCE_DIR}/example" ) + +set ( example_sources + "${example_source_dir}/aaa_demo.cpp" + "${example_source_dir}/bbb_demo.cpp" ) + +set ( OPTIONS "" ) +set ( DEFINITIONS "" ) + +set ( header_dirs + "${include_source_dir}" +# "${test_include_dir}" + ) + +# Still learning find_package and related ways to bring in third party dependent include directories, +# so don't judge, instead please help. + +set ( asio_include_dir "${CMAKE_SOURCE_DIR}/../asio/asio/include" ) +if ( NOT $ENV{ASIO_INCLUDE_DIR} STREQUAL "" ) + set ( asio_include_dir $ENV{ASIO_INCLUDE_DIR}} ) +endif() +set ( boost_include_dir "${CMAKE_SOURCE_DIR}/../boost_1_69_0" ) +if ( NOT $ENV{BOOST_INCLUDE_DIR} STREQUAL "" ) + set ( boost_include_dir $ENV{BOOST_INCLUDE_DIR}} ) +endif() +set ( ring_span_lite_include_dir "${CMAKE_SOURCE_DIR}/../ring-span-lite/include" ) +if ( NOT $ENV{RING_SPAN_LITE_INCLUDE_DIR} STREQUAL "" ) + set ( ring_span_lite_include_dir $ENV{RING_SPAN_LITE_INCLUDE_DIR}} ) +endif() +set ( expected_lite_include_dir "${CMAKE_SOURCE_DIR}/../expected-lite/include" ) +if ( NOT $ENV{EXPECTED_LITE_INCLUDE_DIR} STREQUAL "" ) + set ( expected_lite_include_dir $ENV{EXPECTED_LITE_INCLUDE_DIR}} ) +endif() + +function ( add_target_dependencies target ) +# find_package ( Boost REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${Boost_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${boost_include_dir} ) +# find_package ( asio REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${asio_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${asio_include_dir} ) +# find_package ( ring-span-lite REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${ring-span-lite_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${ring_span_lite_include_dir} ) +# find_package ( expected-lite REQUIRED ) +# target_include_directories ( ${target} PRIVATE ${expected-lite_INCLUDE_DIRS} ) + target_include_directories ( ${target} PRIVATE ${expected_lite_include_dir} ) +endfunction() + +function ( add_target_info target ) + target_compile_features ( ${target} PRIVATE cxx_std_17 ) + target_compile_options ( ${target} PRIVATE ${OPTIONS} ) + target_compile_definitions ( ${target} PRIVATE ${DEFINITIONS} ) + target_include_directories ( ${target} PRIVATE ${header_dirs} ) + add_target_dependencies ( ${target} ) +endfunction() + +function ( make_exe target src ) + add_executable ( ${target} ${src} ) + add_target_info ( ${target} ) + target_link_libraries ( ${target} PRIVATE pthread ) + message ( "Example executable to create: ${target}" ) + add_test ( NAME ${target} COMMAND ${target} ) +endfunction() + +foreach ( example_src IN LISTS example_sources ) + get_filename_component ( targ ${example_src} NAME_WE ) + message ( "Calling make_exe for: ${targ}" ) + make_exe ( ${targ} ${example_src} ) +endforeach() + +# end of file + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 84b00485..993df2a9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,7 +54,7 @@ set ( utility_rack_include_dir "${CMAKE_SOURCE_DIR}/../utility-rack/include" ) if ( NOT $ENV{UTILITY_RACK_INCLUDE_DIR} STREQUAL "" ) set ( utility_rack_include_dir $ENV{UTILITY_RACK_INCLUDE_DIR}} ) endif() -set ( boost_include_dir "${CMAKE_SOURCE_DIR}/../boost_1_68_0" ) +set ( boost_include_dir "${CMAKE_SOURCE_DIR}/../boost_1_69_0" ) if ( NOT $ENV{BOOST_INCLUDE_DIR} STREQUAL "" ) set ( boost_include_dir $ENV{BOOST_INCLUDE_DIR}} ) endif()