diff --git a/CMakeLists.txt b/CMakeLists.txt index ddfe3e7f2..1110be4c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,9 @@ option(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST "Whether to build executables which ar option(LLFIO_ASSUME_CROSS_COMPILING "Whether to assume we are cross compiling. Normally automatically detected, but if automatic detection doesn't work, a working will not be found during cmake configure." OFF) option(LLFIO_FORCE_CONCEPTS_OFF "Whether to not auto detect and enable concepts for the LLFIO cmake targets" OFF) option(LLFIO_FORCE_COROUTINES_OFF "Whether to not auto detect and enable coroutines for the LLFIO cmake targets" OFF) +option(LLFIO_FORCE_DYNAMIC_THREAD_POOL_GROUP_OFF "Whether to disable dynamic thread pool support in LLFIO" OFF) +option(LLFIO_FORCE_NETWORKING_OFF "Whether to disable networking support in LLFIO" OFF) +option(LLFIO_FORCE_MAPPED_FILES_OFF "Whether to disable memory mapped files support in LLFIO" OFF) option(UNIT_TESTS_BUILD_ALL "Whether to run all of the unit test suite." OFF) set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE) @@ -317,29 +320,43 @@ int main() { all_compile_definitions(PUBLIC LLFIO_FORCE_EXPERIMENTAL_FILESYSTEM=1 KERNELTEST_FORCE_EXPERIMENTAL_FILESYSTEM=1) endif() endif() -# Do we have Grand Central Dispatch on this platform? -if(LLFIO_USE_LIBDISPATCH) - function(check_have_libdispatch postfix) - set(CMAKE_REQUIRED_LIBRARIES ${ARGN}) - check_cxx_source_compiles(" -#include -int main() { - return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) != nullptr; -} -" LLFIO_HAS_LIBDISPATCH_${postfix}) - endfunction() - check_have_libdispatch(BUILTIN) - if(NOT LLFIO_HAS_LIBDISPATCH_BUILTIN) - check_have_libdispatch(WITH_LIBDISPATCH dispatch) - if(LLFIO_HAS_LIBDISPATCH_WITH_LIBDISPATCH) - all_link_libraries(PUBLIC dispatch) +if(LLFIO_FORCE_DYNAMIC_THREAD_POOL_GROUP_OFF) + all_compile_definitions(PUBLIC LLFIO_EXCLUDE_DYNAMIC_THREAD_POOL_GROUP=1) +else() + # Do we have Grand Central Dispatch on this platform? + if(LLFIO_USE_LIBDISPATCH) + function(check_have_libdispatch postfix) + set(CMAKE_REQUIRED_LIBRARIES ${ARGN}) + check_cxx_source_compiles(" + #include + int main() { + return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) != nullptr; + } + " LLFIO_HAS_LIBDISPATCH_${postfix}) + endfunction() + check_have_libdispatch(BUILTIN) + if(NOT LLFIO_HAS_LIBDISPATCH_BUILTIN) + check_have_libdispatch(WITH_LIBDISPATCH dispatch) + if(LLFIO_HAS_LIBDISPATCH_WITH_LIBDISPATCH) + all_link_libraries(PUBLIC dispatch) + endif() endif() + else() + all_compile_definitions(PUBLIC LLFIO_DYNAMIC_THREAD_POOL_GROUP_USING_GCD=0) + endif() + if(NOT LLFIO_HAS_LIBDISPATCH_BUILTIN AND NOT LLFIO_HAS_LIBDISPATCH_WITH_LIBDISPATCH AND (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE)) + indented_message(FATAL_ERROR "FATAL: Grand Central Dispatch as libdispatch was not found on this FreeBSD or Mac OS system. libdispatch is required for LLFIO to build on those systems.") endif() +endif() +if(LLFIO_FORCE_NETWORKING_OFF) + all_compile_definitions(PUBLIC LLFIO_EXCLUDE_NETWORKING=1) else() - all_compile_definitions(PUBLIC LLFIO_DYNAMIC_THREAD_POOL_GROUP_USING_GCD=0) + if(WIN32) + all_link_libraries(PUBLIC ws2_32) + endif() endif() -if(NOT LLFIO_HAS_LIBDISPATCH_BUILTIN AND NOT LLFIO_HAS_LIBDISPATCH_WITH_LIBDISPATCH AND (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE)) - indented_message(FATAL_ERROR "FATAL: Grand Central Dispatch as libdispatch was not found on this FreeBSD or Mac OS system. libdispatch is required for LLFIO to build on those systems.") +if(LLFIO_FORCE_MAPPED_FILES_OFF) + all_compile_definitions(PUBLIC LLFIO_EXCLUDE_MAPPED_FILE_HANDLE=1) endif() # Set any macros this library requires diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 3ecb486f0..3fb2a5893 100644 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -24,24 +24,29 @@ 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/byte_socket_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 +64,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 +91,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/cmake/tests.cmake b/cmake/tests.cmake index 9201bd4f2..8e64425f4 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -1,6 +1,7 @@ # DO NOT EDIT, GENERATED BY SCRIPT set(llfio_TESTS "test/test_kernel_decl.hpp" + "test/tests/byte_socket_handle.cpp" "test/tests/clone_extents.cpp" "test/tests/current_path.cpp" "test/tests/directory_handle_create_close/kernel_directory_handle.cpp.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