Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions .github/workflows/windows-msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ on:

jobs:
build:
name: Build & Test (${{ matrix.tls.name }})
name: Build & Test (${{ matrix.arch.name }}, ${{ matrix.build_type }}, ${{ matrix.tls.name }})
runs-on: windows-latest
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
build_type: [Debug]
build_type: [Debug, Release]
std: [23]
arch:
- name: x64
cmake_arch: x64
vcpkg_triplet: x64-windows
build_dir_suffix: x64
- name: x86
cmake_arch: Win32
vcpkg_triplet: x86-windows
build_dir_suffix: x86
tls:
- name: No TLS
cmake_arg: ""
Expand All @@ -30,9 +39,6 @@ jobs:
build_dir: build-wolfssl
use_vcpkg: true

env:
VCPKG_DEFAULT_TRIPLET: x64-windows

steps:
- uses: actions/checkout@v4

Expand All @@ -44,19 +50,22 @@ jobs:

- name: Install wolfSSL (vcpkg)
if: matrix.tls.use_vcpkg
shell: pwsh
run: |
& "$env:VCPKG_ROOT\vcpkg.exe" install "wolfssl[asio]" --triplet "$env:VCPKG_DEFAULT_TRIPLET"
& "$env:VCPKG_ROOT\vcpkg.exe" install "wolfssl[asio]" --triplet "${{ matrix.arch.vcpkg_triplet }}"

- name: Configure CMake
shell: pwsh
run: |
$buildDir = "${{ github.workspace }}/${{ matrix.tls.build_dir }}-${{ matrix.arch.build_dir_suffix }}-${{ matrix.build_type }}"
$vcpkgCmakeArgs = @()
if ("${{ matrix.tls.use_vcpkg }}" -eq "true") {
$vcpkgCmakeArgs += "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
$vcpkgCmakeArgs += "-DVCPKG_TARGET_TRIPLET=$env:VCPKG_DEFAULT_TRIPLET"
$vcpkgCmakeArgs += "-DVCPKG_TARGET_TRIPLET=${{ matrix.arch.vcpkg_triplet }}"
}

cmake -B "${{ github.workspace }}/${{ matrix.tls.build_dir }}" `
cmake -B $buildDir `
-A "${{ matrix.arch.cmake_arch }}" `
-DCMAKE_CXX_STANDARD=${{ matrix.std }} `
-DCMAKE_CXX_STANDARD_REQUIRED=ON `
-DCMAKE_CXX_EXTENSIONS=OFF `
Expand All @@ -65,8 +74,14 @@ jobs:
$vcpkgCmakeArgs

- name: Build
run: cmake --build "${{ github.workspace }}/${{ matrix.tls.build_dir }}" --config ${{ matrix.build_type }} --parallel
shell: pwsh
run: |
$buildDir = "${{ github.workspace }}/${{ matrix.tls.build_dir }}-${{ matrix.arch.build_dir_suffix }}-${{ matrix.build_type }}"
cmake --build $buildDir --config ${{ matrix.build_type }} --parallel

- name: Test
working-directory: ${{ github.workspace }}/${{ matrix.tls.build_dir }}
run: ctest --output-on-failure -C ${{ matrix.build_type }}
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$buildDir = "${{ github.workspace }}/${{ matrix.tls.build_dir }}-${{ matrix.arch.build_dir_suffix }}-${{ matrix.build_type }}"
ctest --test-dir $buildDir --output-on-failure -C ${{ matrix.build_type }}
4 changes: 0 additions & 4 deletions cmake/AeroUseAsio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ include(FetchContent)

set(AERO_ASIO_DEFINITIONS
ASIO_STANDALONE
ASIO_NO_DEPRECATED
ASIO_NO_TS_EXECUTORS
ASIO_DISABLE_BUFFER_DEBUGGING
ASIO_NO_TYPEID
)

function(_aero_select_first_existing_asio_target out_var)
Expand Down
48 changes: 48 additions & 0 deletions include/aero/detail/aligned_allocator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef AERO_DETAIL_ALIGNED_ALLOCATOR_HPP
#define AERO_DETAIL_ALIGNED_ALLOCATOR_HPP

#include <asio/recycling_allocator.hpp>
#include <cstddef>

namespace aero::detail {

constexpr inline std::size_t default_allocator_alignment = 16;

// See https://github.com/chriskohlhoff/asio/pull/1724
template <typename T = std::byte, std::size_t Alignment = default_allocator_alignment>
struct alignas(Alignment < alignof(T) ? alignof(T) : Alignment) aligned_allocator {
using value_type = T;
using is_always_equal = std::true_type;

aligned_allocator() noexcept = default;

template <typename OtherT>
explicit aligned_allocator(const aligned_allocator<OtherT, Alignment>&) noexcept {}

template <typename OtherT>
struct rebind {
using other = aligned_allocator<OtherT, Alignment>;
};

[[nodiscard]] T* allocate(std::size_t element_count) {
return asio::recycling_allocator<T>{}.allocate(element_count);
}

void deallocate(T* pointer, std::size_t element_count) noexcept {
asio::recycling_allocator<T>{}.deallocate(pointer, element_count);
}

template <typename OtherT>
bool operator==(const aligned_allocator<OtherT, Alignment>&) const noexcept {
return true;
}

template <typename OtherT>
bool operator!=(const aligned_allocator<OtherT, Alignment>&) const noexcept {
return false;
}
};

} // namespace aero::detail

#endif
20 changes: 14 additions & 6 deletions include/aero/net/detail/basic_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <asio/async_result.hpp>
#include <asio/awaitable.hpp>
#include <asio/basic_stream_socket.hpp>
#include <asio/bind_allocator.hpp>
#include <asio/buffer.hpp>
#include <asio/co_composed.hpp>
#include <asio/co_spawn.hpp>
Expand All @@ -25,6 +26,7 @@
#include <asio/strand.hpp>
#include <asio/write.hpp>

#include "aero/detail/aligned_allocator.hpp"
#include "aero/net/concepts/transport.hpp"

namespace aero::net::detail {
Expand Down Expand Up @@ -70,7 +72,9 @@ namespace aero::net::detail {

template <typename CompletionToken>
auto async_read_some(CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code, const_buffer)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code, const_buffer)>(
asio::co_composed<void(std::error_code, const_buffer)>(
[this](auto) -> void {
auto [read_ec, bytes_read] = co_await stream_.async_read_some(get_mutable_buffer(), asio::as_tuple(asio::deferred));
Expand All @@ -80,7 +84,7 @@ namespace aero::net::detail {
co_return {std::error_code{}, get_buffer_view(0, bytes_read)};
},
strand_),
token);
bound_token);
}

template <typename CompletionToken>
Expand All @@ -90,7 +94,9 @@ namespace aero::net::detail {

template <typename CompletionToken>
auto async_read_exactly(std::size_t bytes_count, CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code, const_buffer)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code, const_buffer)>(
asio::co_composed<void(std::error_code, const_buffer)>(
[this, bytes_count](auto) -> void {
auto [read_ec, bytes_read] = co_await asio::async_read(stream_,
Expand All @@ -103,12 +109,14 @@ namespace aero::net::detail {
co_return {std::error_code{}, get_buffer_view(0, bytes_read)};
},
strand_),
token);
bound_token);
}

template <typename CompletionToken>
auto async_write(const_buffer buffer, CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code, std::size_t)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code, std::size_t)>(
asio::co_composed<void(std::error_code, std::size_t)>(
[this](auto, const_buffer buffer) -> void {
asio::const_buffer asio_buffer(buffer.data(), buffer.size());
Expand All @@ -128,7 +136,7 @@ namespace aero::net::detail {
co_return {write_request->result.ec, write_request->result.bytes_written};
},
strand_),
token,
bound_token,
buffer);
}

Expand Down
14 changes: 10 additions & 4 deletions include/aero/net/tcp_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include <asio/async_result.hpp>
#include <asio/bind_allocator.hpp>
#include <asio/co_composed.hpp>
#include <asio/connect.hpp>
#include <asio/error.hpp>
Expand All @@ -18,6 +19,7 @@
#include <asio/redirect_error.hpp>
#include <asio/strand.hpp>

#include "aero/detail/aligned_allocator.hpp"
#include "aero/net/concepts/transport.hpp"
#include "aero/net/detail/basic_transport.hpp"
#include "aero/net/error.hpp"
Expand All @@ -40,7 +42,9 @@ namespace aero::net {

template <typename CompletionToken>
auto async_connect(std::string host, port_type port, CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code)>(
asio::co_composed<void(std::error_code)>(
[this](auto, std::string host, port_type port) -> void {
using net::error::connect_error;
Expand Down Expand Up @@ -79,14 +83,16 @@ namespace aero::net {
co_return std::error_code{};
},
get_strand()),
token,
bound_token,
std::move(host),
port);
}

template <typename CompletionToken>
auto async_shutdown(CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code)>(
asio::co_composed<void(std::error_code)>(
[this](auto) -> void {
resolver_.cancel();
Expand All @@ -108,7 +114,7 @@ namespace aero::net {
co_return shutdown_ec ? shutdown_ec : close_ec;
},
get_strand()),
token);
bound_token);
}

template <typename CompletionToken>
Expand Down
20 changes: 14 additions & 6 deletions include/aero/net/tls_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include <asio/async_result.hpp>
#include <asio/bind_allocator.hpp>
#include <asio/co_composed.hpp>
#include <asio/connect.hpp>
#include <asio/error.hpp>
Expand All @@ -19,6 +20,7 @@
#include <asio/ssl/stream.hpp>
#include <asio/strand.hpp>

#include "aero/detail/aligned_allocator.hpp"
#include "aero/net/concepts/transport.hpp"
#include "aero/net/detail/basic_transport.hpp"
#include "aero/net/error.hpp"
Expand Down Expand Up @@ -71,7 +73,9 @@ namespace aero::net {

template <typename CompletionToken>
auto async_connect(std::string host, port_type port, CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code)>(
asio::co_composed<void(std::error_code)>(
[this](auto, std::string host, port_type port) -> void {
using net::error::connect_error;
Expand Down Expand Up @@ -121,14 +125,16 @@ namespace aero::net {
co_return co_await this->async_handshake(asio::as_tuple(asio::deferred));
},
get_strand()),
token,
bound_token,
std::move(host),
port);
}

template <typename CompletionToken>
auto async_shutdown(CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code)>(
asio::co_composed<void(std::error_code)>(
[this](auto) -> void {
resolver_.cancel();
Expand All @@ -150,7 +156,7 @@ namespace aero::net {
co_return shutdown_ec ? shutdown_ec : close_ec;
},
get_strand()),
token);
bound_token);
}

template <typename CompletionToken>
Expand Down Expand Up @@ -200,7 +206,9 @@ namespace aero::net {

template <typename CompletionToken>
auto async_handshake(CompletionToken&& token) {
return asio::async_initiate<CompletionToken, void(std::error_code)>(
auto bound_token = asio::bind_allocator(aero::detail::aligned_allocator<>{}, std::forward<CompletionToken>(token));

return asio::async_initiate<decltype(bound_token), void(std::error_code)>(
asio::co_composed<void(std::error_code)>(
[this](auto) -> void {
using tls::detail::x509_verify_error;
Expand Down Expand Up @@ -231,7 +239,7 @@ namespace aero::net {
co_return handshake_ec;
},
get_strand()),
token);
bound_token);
}

net::detail::basic_transport<stream_type> basic_transport_;
Expand Down
Loading
Loading