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
38 changes: 38 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Checks: '
*,
-llvmlibc-*,
-google-readability-todo,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-pro-type-reinterpret-cast,
-android-*,
-altera-*,
-llvm-namespace-comment,
-readability-implicit-bool-conversion,
-google-explicit-constructor,
-fuchsia-overloaded-operator,

-google-readability-braces-around-statements,
-google-readability-namespace-comments,
-hicpp-braces-around-statements,
-hicpp-explicit-conversions,
-fuchsia-trailing-return
'

WarningsAsErrors: 'bugprone-exception-escape'
FormatStyle: 'none' # TODO: Replace with 'file' once we have a proper .clang-format file
InheritParentConfig: true
CheckOptions:
misc-include-cleaner.MissingIncludes: 'false'
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection\.hpp'

bugprone-argument-comment.StrictMode: 1

# Readability
readability-braces-around-statements.ShortStatementLines: 2

readability-identifier-naming.NamespaceCase: CamelCase

readability-identifier-length.IgnoredVariableNames: "^(fd|nb|ss)$"
readability-identifier-length.IgnoredParameterNames: "^([n]|fd)$"
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
cpp_indent_case_contents_when_block = true
cpp_new_line_before_open_brace_namespace = same_line
indent_size = 4
indent_style = space
135 changes: 86 additions & 49 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
types: [ "opened", "reopened", "synchronize", "ready_for_review" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false # ensure we don't stop after 1 failure to always have a complete picture of what is failing
# ensure we don't stop after 1 failure to always have a complete picture of what is failing
fail-fast: false

# Set up a matrix to run the following configurations:
# - ubuntu Debug/Release clang/gcc
# - windows Debug/Release cl
# - macos Debug/Release clang
matrix:
os: [ubuntu-latest, macos-latest] # , windows-latest
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [Release, Debug]
c_compiler: [gcc, clang, cl]
include:
# - os: windows-latest
# c_compiler: cl
# cpp_compiler: cl
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
Expand All @@ -47,47 +49,82 @@ jobs:
c_compiler: gcc

steps:
- uses: actions/checkout@v3

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Cache VCPKG (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: ${{ env.VCPKG_ROOT }}
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}

- name: Install OpenSSL (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCPPSOCKETS_TESTS=TRUE
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }} --test-dir tests
- uses: actions/checkout@v3

- name: Set Env
shell: bash
run: |
echo "VCPKG_ROOT=${VCPKG_INSTALLATION_ROOT}" >> "$GITHUB_ENV"
echo "BUILD_OUTPUT_DIR=${{ github.workspace }}/build" >> "$GITHUB_ENV"

- name: Fetch VCPKG Cache (Windows)
id: fetch-vcpkg-cache
if: runner.os == 'Windows'
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}
path: ${{ env.VCPKG_ROOT }}

- name: Install OpenSSL (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install

- name: Always Save VCPKG Cache (Windows)
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
path: ${{ env.VCPKG_ROOT }}

- name: Configure CMake
# Configure CMake in a 'build' subdirectory.
# `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ env.BUILD_OUTPUT_DIR }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCPPSOCKETS_TESTS=TRUE
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed
# because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ env.BUILD_OUTPUT_DIR }} --config ${{ matrix.build_type }}

- uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'Release' && matrix.c_compiler == 'clang'
with:
name: compile_commands.json
path: ${{ env.BUILD_OUTPUT_DIR }}/compile_commands.json

- name: Test
working-directory: ${{ env.BUILD_OUTPUT_DIR }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed
# because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }} --test-dir tests --output-on-failure

clang-tidy:
needs: 'build'
runs-on: ubuntu-latest
if: always()

steps:
- name: Checkout Code
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: compile_commands.json

- name: clang-tidy review
uses: ZedThree/clang-tidy-review@v0.21.0

# If there are any comments, fail the check
- if: steps.review.outputs.total_comments > 0
run: exit 1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
build/

libcppsockets.so
compile_commands.json

*.tmp
*.gch
vgcore.*

.vscode/
.cache/
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Author Francois Michaut
##
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
## Last update Sat Dec 2 17:45:28 2023 Francois Michaut
## Last update Mon Aug 4 23:34:08 2025 Francois Michaut
##
## CMakeLists.txt : CMake to build the CppSockets library
##
Expand All @@ -22,7 +22,9 @@ configure_file(include/CppSockets/Version.hpp.in include/CppSockets/Version.hpp)

add_library(cppsockets
source/Address.cpp
source/Certificate.cpp
source/IPv4.cpp
source/SSL_Utils.cpp
source/Socket.cpp
source/SocketInit.cpp
source/TlsSocket.cpp
Expand Down
20 changes: 10 additions & 10 deletions include/CppSockets/Address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
namespace CppSockets {
class IAddress {
public:
[[nodiscard]] virtual std::uint32_t getAddress() const = 0;
[[nodiscard]] virtual int getFamily() const = 0;
[[nodiscard]] virtual const std::string &toString() const = 0;
[[nodiscard]] virtual auto getAddress() const -> std::uint32_t = 0;
[[nodiscard]] virtual auto getFamily() const -> int = 0;
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;
};

class IEndpoint {
public:
[[nodiscard]] virtual std::uint16_t getPort() const = 0;
[[nodiscard]] virtual const IAddress &getAddr() const = 0;
[[nodiscard]] virtual const std::string &toString() const = 0;
[[nodiscard]] virtual auto getPort() const -> std::uint16_t = 0;
[[nodiscard]] virtual auto getAddr() const -> const IAddress & = 0;
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;

protected:
[[nodiscard]] std::string makeString() const;
[[nodiscard]] auto makeString() const -> std::string;
};

template <class T>
Expand All @@ -46,15 +46,15 @@ namespace CppSockets {
{};
virtual ~Endpoint() = default;

[[nodiscard]] std::uint16_t getPort() const override {
[[nodiscard]] auto getPort() const -> std::uint16_t override {
return port;
}

[[nodiscard]] const T &getAddr() const override {
[[nodiscard]] auto getAddr() const -> const T & override {
return addr;
}

[[nodiscard]] const std::string &toString() const override {
[[nodiscard]] auto toString() const -> const std::string & override {
return str;
}
private:
Expand Down
Loading
Loading