Skip to content

Commit

Permalink
Merge pull request #84 from ned14/networking
Browse files Browse the repository at this point in the history
Networking
  • Loading branch information
ned14 authored Dec 23, 2021
2 parents bfa6737 + d5717dc commit 47b0e2f
Show file tree
Hide file tree
Showing 57 changed files with 4,233 additions and 837 deletions.
55 changes: 36 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filesystem> 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)
Expand Down Expand Up @@ -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 <dispatch/dispatch.h>
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 <dispatch/dispatch.h>
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
Expand Down
21 changes: 13 additions & 8 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
20 changes: 10 additions & 10 deletions example/ts_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ using namespace std;
#define throws(x)
#define VALUE .value()

inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request<io_handle::buffers_type> 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<byte_io_handle::buffers_type> reqs, deadline d = deadline()) throws(file_io_error)
{
// Record beginning if deadline is specified
chrono::steady_clock::time_point began_steady;
if(d && d.steady)
began_steady = chrono::steady_clock::now();

// Take copy of input buffers onto stack, and set output buffers to buffers supplied
auto *input_buffers_mem = reinterpret_cast<io_handle::buffer_type *>(alloca(reqs.buffers.size() * sizeof(io_handle::buffer_type)));
auto *input_buffers_sizes = reinterpret_cast<io_handle::size_type *>(alloca(reqs.buffers.size() * sizeof(io_handle::size_type)));
io_handle::buffers_type output_buffers(reqs.buffers);
io_handle::io_request<io_handle::buffers_type> creq({input_buffers_mem, reqs.buffers.size()}, 0);
auto *input_buffers_mem = reinterpret_cast<byte_io_handle::buffer_type *>(alloca(reqs.buffers.size() * sizeof(byte_io_handle::buffer_type)));
auto *input_buffers_sizes = reinterpret_cast<byte_io_handle::size_type *>(alloca(reqs.buffers.size() * sizeof(byte_io_handle::size_type)));
byte_io_handle::buffers_type output_buffers(reqs.buffers);
byte_io_handle::io_request<byte_io_handle::buffers_type> 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
Expand All @@ -71,7 +71,7 @@ inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request<io_h
nd = d;
}
// Partial fill buffers with current request
io_handle::buffers_type filled = h.read(creq, nd) VALUE;
byte_io_handle::buffers_type filled = h.read(creq, nd) VALUE;
(void) filled;

// Adjust output buffers by what was filled, and prepare input
Expand All @@ -82,15 +82,15 @@ inline io_handle::buffers_type read_all(io_handle &h, io_handle::io_request<io_h
auto &input_buffer = creq.buffers[n];
auto &output_buffer = output_buffers[idx + n];
creq.offset += input_buffer.size();
output_buffer = io_handle::buffer_type{output_buffer.data(), output_buffer.size() + input_buffer.size()};
output_buffer = byte_io_handle::buffer_type{output_buffer.data(), output_buffer.size() + input_buffer.size()};
// Adjust input buffer to amount remaining
input_buffer = io_handle::buffer_type{input_buffer.data() + input_buffer.size(), input_buffers_sizes[idx + n] - output_buffer.size()};
input_buffer = byte_io_handle::buffer_type{input_buffer.data() + input_buffer.size(), input_buffers_sizes[idx + n] - output_buffer.size()};
}

// Remove completely filled input buffers
while(!creq.buffers.empty() && creq.buffers[0].size() == 0)
{
creq.buffers = io_handle::buffers_type(creq.buffers.data() + 1, creq.buffers.size() - 1);
creq.buffers = byte_io_handle::buffers_type(creq.buffers.data() + 1, creq.buffers.size() - 1);
++idx;
}
} while(!creq.buffers.empty());
Expand Down
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define LLFIO_PREVIOUS_COMMIT_REF fba45d6bacbdc7710e257a0b3d229fe3ef3a1f5d
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-12-14 16:26:38 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE fba45d6b
#define LLFIO_PREVIOUS_COMMIT_REF 0906bce16f8767db4ecdbe3992eaf0f62c6dc0fe
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-12-21 21:17:38 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 0906bce1
Loading

0 comments on commit 47b0e2f

Please sign in to comment.