From 720d79da5abd0b3fc895faccdb2e2513c0d61d6f Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Mon, 20 Dec 2021 02:16:41 +0000 Subject: [PATCH 01/13] Rename io_handle to byte_io_handle. Rename io_multiplexer to byte_io_multiplexer. Add declaration of byte_socket_handle. --- cmake/headers.cmake | 20 +- example/ts_examples.cpp | 20 +- include/llfio/revision.hpp | 6 +- .../algorithm/handle_adapter/combining.hpp | 94 ++--- .../{io_handle.hpp => byte_io_handle.hpp} | 80 ++-- ...ultiplexer.hpp => byte_io_multiplexer.hpp} | 115 +++--- include/llfio/v2.0/byte_socket_handle.hpp | 372 ++++++++++++++++++ ...ultiplexer.ipp => byte_io_multiplexer.ipp} | 12 +- .../v2.0/detail/impl/byte_socket_handle.ipp | 118 ++++++ .../detail/impl/dynamic_thread_pool_group.ipp | 4 +- .../{io_handle.ipp => byte_io_handle.ipp} | 16 +- .../v2.0/detail/impl/posix/file_handle.ipp | 2 +- ...handle.ipp => lockable_byte_io_handle.ipp} | 20 +- .../impl/posix/test/io_uring_multiplexer.ipp | 50 +-- .../v2.0/detail/impl/storage_profile.ipp | 14 +- .../detail/impl/test/null_multiplexer.ipp | 54 +-- .../{io_handle.ipp => byte_io_handle.ipp} | 18 +- .../impl/windows/byte_io_multiplexer.ipp | 55 +++ .../impl/windows/byte_socket_handle.ipp | 39 ++ .../v2.0/detail/impl/windows/file_handle.ipp | 2 +- .../llfio/v2.0/detail/impl/windows/import.hpp | 4 +- ...handle.ipp => lockable_byte_io_handle.ipp} | 18 +- .../v2.0/detail/impl/windows/pipe_handle.ipp | 4 +- .../impl/windows/test/iocp_multiplexer.ipp | 26 +- .../llfio/v2.0/dynamic_thread_pool_group.hpp | 14 +- .../llfio/v2.0/fast_random_file_handle.hpp | 26 +- include/llfio/v2.0/file_handle.hpp | 66 ++-- include/llfio/v2.0/llfio.hpp | 3 + ...handle.hpp => lockable_byte_io_handle.hpp} | 90 ++--- include/llfio/v2.0/map_handle.hpp | 54 +-- include/llfio/v2.0/mapped_file_handle.hpp | 28 +- include/llfio/v2.0/multiplex.hpp | 12 +- include/llfio/v2.0/pipe_handle.hpp | 62 +-- include/llfio/v2.0/storage_profile.hpp | 18 +- programs/benchmark-async/main.cpp | 48 +-- programs/benchmark-io-congestion/main.cpp | 8 +- test/tests/dynamic_thread_pool_group.cpp | 2 +- test/tests/pipe_handle.cpp | 18 +- 38 files changed, 1102 insertions(+), 510 deletions(-) rename include/llfio/v2.0/{io_handle.hpp => byte_io_handle.hpp} (89%) rename include/llfio/v2.0/{io_multiplexer.hpp => byte_io_multiplexer.hpp} (91%) create mode 100644 include/llfio/v2.0/byte_socket_handle.hpp rename include/llfio/v2.0/detail/impl/{io_multiplexer.ipp => byte_io_multiplexer.ipp} (71%) create mode 100644 include/llfio/v2.0/detail/impl/byte_socket_handle.ipp rename include/llfio/v2.0/detail/impl/posix/{io_handle.ipp => byte_io_handle.ipp} (88%) rename include/llfio/v2.0/detail/impl/posix/{lockable_io_handle.ipp => lockable_byte_io_handle.ipp} (85%) rename include/llfio/v2.0/detail/impl/windows/{io_handle.ipp => byte_io_handle.ipp} (85%) create mode 100644 include/llfio/v2.0/detail/impl/windows/byte_io_multiplexer.ipp create mode 100644 include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp rename include/llfio/v2.0/detail/impl/windows/{lockable_io_handle.ipp => lockable_byte_io_handle.ipp} (72%) rename include/llfio/v2.0/{lockable_io_handle.hpp => lockable_byte_io_handle.hpp} (84%) diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 3ecb486f0..cf946ef46 100644 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -24,24 +24,28 @@ set(llfio_HEADERS "include/llfio/v2.0/algorithm/summarize.hpp" "include/llfio/v2.0/algorithm/traverse.hpp" "include/llfio/v2.0/algorithm/trivial_vector.hpp" + "include/llfio/v2.0/byte_io_handle.hpp" + "include/llfio/v2.0/byte_io_multiplexer.hpp" + "include/llfio/v2.0/byte_socket_handle.hpp" "include/llfio/v2.0/config.hpp" "include/llfio/v2.0/deadline.h" + "include/llfio/v2.0/detail/impl/byte_io_multiplexer.ipp" + "include/llfio/v2.0/detail/impl/byte_socket_handle.ipp" "include/llfio/v2.0/detail/impl/cached_parent_handle_adapter.ipp" "include/llfio/v2.0/detail/impl/clone.ipp" "include/llfio/v2.0/detail/impl/config.ipp" "include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp" "include/llfio/v2.0/detail/impl/fast_random_file_handle.ipp" - "include/llfio/v2.0/detail/impl/io_multiplexer.ipp" "include/llfio/v2.0/detail/impl/map_handle.ipp" "include/llfio/v2.0/detail/impl/path_discovery.ipp" "include/llfio/v2.0/detail/impl/path_view.ipp" + "include/llfio/v2.0/detail/impl/posix/byte_io_handle.ipp" "include/llfio/v2.0/detail/impl/posix/directory_handle.ipp" "include/llfio/v2.0/detail/impl/posix/file_handle.ipp" "include/llfio/v2.0/detail/impl/posix/fs_handle.ipp" "include/llfio/v2.0/detail/impl/posix/handle.ipp" "include/llfio/v2.0/detail/impl/posix/import.hpp" - "include/llfio/v2.0/detail/impl/posix/io_handle.ipp" - "include/llfio/v2.0/detail/impl/posix/lockable_io_handle.ipp" + "include/llfio/v2.0/detail/impl/posix/lockable_byte_io_handle.ipp" "include/llfio/v2.0/detail/impl/posix/map_handle.ipp" "include/llfio/v2.0/detail/impl/posix/mapped_file_handle.ipp" "include/llfio/v2.0/detail/impl/posix/path_discovery.ipp" @@ -59,13 +63,15 @@ set(llfio_HEADERS "include/llfio/v2.0/detail/impl/storage_profile.ipp" "include/llfio/v2.0/detail/impl/test/null_multiplexer.ipp" "include/llfio/v2.0/detail/impl/traverse.ipp" + "include/llfio/v2.0/detail/impl/windows/byte_io_handle.ipp" + "include/llfio/v2.0/detail/impl/windows/byte_io_multiplexer.ipp" + "include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp" "include/llfio/v2.0/detail/impl/windows/directory_handle.ipp" "include/llfio/v2.0/detail/impl/windows/file_handle.ipp" "include/llfio/v2.0/detail/impl/windows/fs_handle.ipp" "include/llfio/v2.0/detail/impl/windows/handle.ipp" "include/llfio/v2.0/detail/impl/windows/import.hpp" - "include/llfio/v2.0/detail/impl/windows/io_handle.ipp" - "include/llfio/v2.0/detail/impl/windows/lockable_io_handle.ipp" + "include/llfio/v2.0/detail/impl/windows/lockable_byte_io_handle.ipp" "include/llfio/v2.0/detail/impl/windows/map_handle.ipp" "include/llfio/v2.0/detail/impl/windows/mapped_file_handle.ipp" "include/llfio/v2.0/detail/impl/windows/path_discovery.ipp" @@ -84,10 +90,8 @@ set(llfio_HEADERS "include/llfio/v2.0/file_handle.hpp" "include/llfio/v2.0/fs_handle.hpp" "include/llfio/v2.0/handle.hpp" - "include/llfio/v2.0/io_handle.hpp" - "include/llfio/v2.0/io_multiplexer.hpp" "include/llfio/v2.0/llfio.hpp" - "include/llfio/v2.0/lockable_io_handle.hpp" + "include/llfio/v2.0/lockable_byte_io_handle.hpp" "include/llfio/v2.0/logging.hpp" "include/llfio/v2.0/map_handle.hpp" "include/llfio/v2.0/mapped.hpp" diff --git a/example/ts_examples.cpp b/example/ts_examples.cpp index b0f81cf54..fed56b79b 100644 --- a/example/ts_examples.cpp +++ b/example/ts_examples.cpp @@ -30,7 +30,7 @@ using namespace std; #define throws(x) #define VALUE .value() -inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request reqs, deadline d = deadline()) throws(file_io_error) +inline byte_io_handle::buffers_type read_all(byte_io_handle &h, byte_io_handle::io_request reqs, deadline d = deadline()) throws(file_io_error) { // Record beginning if deadline is specified chrono::steady_clock::time_point began_steady; @@ -38,17 +38,17 @@ inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request(alloca(reqs.buffers.size() * sizeof(io_handle::buffer_type))); - auto *input_buffers_sizes = reinterpret_cast(alloca(reqs.buffers.size() * sizeof(io_handle::size_type))); - io_handle::buffers_type output_buffers(reqs.buffers); - io_handle::io_request creq({input_buffers_mem, reqs.buffers.size()}, 0); + auto *input_buffers_mem = reinterpret_cast(alloca(reqs.buffers.size() * sizeof(byte_io_handle::buffer_type))); + auto *input_buffers_sizes = reinterpret_cast(alloca(reqs.buffers.size() * sizeof(byte_io_handle::size_type))); + byte_io_handle::buffers_type output_buffers(reqs.buffers); + byte_io_handle::io_request creq({input_buffers_mem, reqs.buffers.size()}, 0); for(size_t n = 0; n < reqs.buffers.size(); n++) { // Copy input buffer to stack and retain original size creq.buffers[n] = reqs.buffers[n]; input_buffers_sizes[n] = reqs.buffers[n].size(); // Set output buffer length to zero - output_buffers[n] = io_handle::buffer_type{output_buffers[n].data(), 0}; + output_buffers[n] = byte_io_handle::buffer_type{output_buffers[n].data(), 0}; } // Track which output buffer we are currently filling @@ -71,7 +71,7 @@ inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request::value && (std::is_void::value || std::is_base_of::value), // file_handle_wrapper, // - io_handle // + byte_io_handle // >; template struct is_void_or_io_request_compatible { @@ -64,26 +64,26 @@ namespace algorithm static_assert(is_void_or_io_request_compatible::value, "Combined handle types do not share io_request"); public: - using path_type = io_handle::path_type; - using extent_type = io_handle::extent_type; - using size_type = io_handle::size_type; - using mode = io_handle::mode; - using creation = io_handle::creation; - using caching = io_handle::caching; - using flag = io_handle::flag; - using buffer_type = io_handle::buffer_type; - using const_buffer_type = io_handle::const_buffer_type; - using buffers_type = io_handle::buffers_type; - using const_buffers_type = io_handle::const_buffers_type; - template using io_request = io_handle::io_request; - template using io_result = io_handle::io_result; + using path_type = byte_io_handle::path_type; + using extent_type = byte_io_handle::extent_type; + using size_type = byte_io_handle::size_type; + using mode = byte_io_handle::mode; + using creation = byte_io_handle::creation; + using caching = byte_io_handle::caching; + using flag = byte_io_handle::flag; + using buffer_type = byte_io_handle::buffer_type; + using const_buffer_type = byte_io_handle::const_buffer_type; + using buffers_type = byte_io_handle::buffers_type; + using const_buffers_type = byte_io_handle::const_buffers_type; + template using io_request = byte_io_handle::io_request; + template using io_result = byte_io_handle::io_result; using target_handle_type = Target; using source_handle_type = Source; protected: static constexpr bool _have_source = !std::is_void::value; - using _source_handle_type = std::conditional_t; + using _source_handle_type = std::conditional_t; target_handle_type *_target{nullptr}; _source_handle_type *_source{nullptr}; @@ -115,13 +115,13 @@ namespace algorithm protected: combining_handle_adapter_base() = default; - constexpr combining_handle_adapter_base(target_handle_type *a, _source_handle_type *b, mode _mode, flag flags, io_multiplexer *ctx) + constexpr combining_handle_adapter_base(target_handle_type *a, _source_handle_type *b, mode _mode, flag flags, byte_io_multiplexer *ctx) : Base(_native_handle(_mode), _combine_caching(a, b), flags, ctx) , _target(a) , _source(b) { } - combining_handle_adapter_base(target_handle_type *a, void *b, mode _mode, flag flags, io_multiplexer *ctx) + combining_handle_adapter_base(target_handle_type *a, void *b, mode _mode, flag flags, byte_io_multiplexer *ctx) : Base(_native_handle(_mode), a->caching(), flags, ctx) , _target(a) , _source(reinterpret_cast<_source_handle_type *>(b)) @@ -315,19 +315,19 @@ namespace algorithm static constexpr bool _have_source = _base::_have_source; public: - using path_type = io_handle::path_type; - using extent_type = io_handle::extent_type; - using size_type = io_handle::size_type; - using mode = io_handle::mode; - using creation = io_handle::creation; - using caching = io_handle::caching; - using flag = io_handle::flag; - using buffer_type = io_handle::buffer_type; - using const_buffer_type = io_handle::const_buffer_type; - using buffers_type = io_handle::buffers_type; - using const_buffers_type = io_handle::const_buffers_type; - template using io_request = io_handle::io_request; - template using io_result = io_handle::io_result; + using path_type = byte_io_handle::path_type; + using extent_type = byte_io_handle::extent_type; + using size_type = byte_io_handle::size_type; + using mode = byte_io_handle::mode; + using creation = byte_io_handle::creation; + using caching = byte_io_handle::caching; + using flag = byte_io_handle::flag; + using buffer_type = byte_io_handle::buffer_type; + using const_buffer_type = byte_io_handle::const_buffer_type; + using buffers_type = byte_io_handle::buffers_type; + using const_buffers_type = byte_io_handle::const_buffers_type; + template using io_request = byte_io_handle::io_request; + template using io_result = byte_io_handle::io_result; combining_handle_adapter_base() = default; using _base::_base; @@ -505,7 +505,7 @@ namespace algorithm If both input handle types have a base of `file_handle`, `combining_handle_adapter` inherits from `file_handle` and provides the extra member functions which `file_handle` - provides over `io_handle`. If not, it inherits from `io_handle`, and provides that + provides over `byte_io_handle`. If not, it inherits from `byte_io_handle`, and provides that class' reduced functionality instead. The default implementation of `read()` and `write()` allocate temporary buffers, and @@ -533,7 +533,7 @@ namespace algorithm Destroying the adapter does not destroy the attached handles. Closing the adapter does close the attached handles. - \todo I have been lazy and used public inheritance from `io_handle` and `file_handle`. + \todo I have been lazy and used public inheritance from `byte_io_handle` and `file_handle`. I should use protected inheritance to prevent slicing, and expose all the public functions by hand. */ template