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
43 changes: 37 additions & 6 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
c_compiler: gcc

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- name: Set Env
shell: bash
Expand All @@ -60,7 +60,7 @@ jobs:
if: runner.os == 'Windows'
uses: ./.github/workflows/windows-vcpkg
with:
key: ${{ runner.os }}-${{ matrix.build_type }}
key: vcpkg-cache-${{ runner.os }}

- name: Configure CMake
# Configure CMake in a 'build' subdirectory.
Expand All @@ -79,18 +79,49 @@ jobs:
# 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
- name: Upload Compile Commands
uses: actions/upload-artifact@v7
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
archive: false

- name: Upload CppSockets lib
uses: actions/upload-artifact@v6
with:
name: libcppsockets-${{ runner.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
path: "${{ env.BUILD_OUTPUT_DIR }}/**/libcppsockets.*"

- name: Upload UnitTests
uses: actions/upload-artifact@v6
if: matrix.os != 'windows-latest'
with:
name: unit_tests-${{ runner.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
path: "${{ env.BUILD_OUTPUT_DIR }}/tests/**/unit_tests*"

- name: Upload UnitTests
uses: actions/upload-artifact@v6
if: matrix.os == 'windows-latest'
with:
name: unit_tests-${{ runner.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
path: |
${{ env.BUILD_OUTPUT_DIR }}/tests/**/unit_tests*
${{ env.BUILD_OUTPUT_DIR }}/tests/**/*.dll

- name: Setup DLL PATH (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
echo "$VCPKG_ROOT/installed/x64-windows/bin" >> "$GITHUB_PATH"
echo "$BUILD_OUTPUT_DIR/${{ matrix.build_type }}" >> "$GITHUB_PATH"

- 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
run: ctest --timeout 60 --build-config ${{ matrix.build_type }} --test-dir tests --output-on-failure

clang-tidy:
needs: 'build'
Expand All @@ -99,9 +130,9 @@ jobs:

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

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code_scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v7

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v7

- name: VCPKG Install (Windows)
uses: ./.github/workflows/windows-vcpkg
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows-vcpkg/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
- name: Fetch VCPKG Cache (Windows)
id: fetch-vcpkg-cache
if: runner.os == 'Windows'
uses: actions/cache/restore@v4
uses: actions/cache/restore@v6
with:
key: ${{ inputs.key }}-vcpkg-${{ hashFiles('vcpkg.json') }}
path: ${{ env.VCPKG_CACHE }}
Expand All @@ -31,7 +31,7 @@ runs:

- name: Always Save VCPKG Cache (Windows)
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
uses: actions/cache/save@v6
with:
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
path: ${{ env.VCPKG_CACHE }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
build/

libcppsockets.so
file-share
file-share-cli
*.so
*.dll
*.exe
compile_commands.json

*.tmp
Expand Down
5 changes: 4 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 Wed Aug 20 17:05:18 2025 Francois Michaut
## Last update Thu Jul 2 01:56:37 2026 Francois Michaut
##
## CMakeLists.txt : CMake to build the CppSockets library
##
Expand All @@ -31,6 +31,7 @@ add_library(cppsockets
source/Socket.cpp
source/SocketInit.cpp
)

target_include_directories(cppsockets
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -39,6 +40,8 @@ target_include_directories(cppsockets
${PROJECT_SOURCE_DIR}/private
)

target_compile_definitions(cppsockets PRIVATE CPPSOCKETS_DLL_EXPORTS=1)

find_package(OpenSSL 3.0 COMPONENTS SSL)
target_link_libraries(cppsockets OpenSSL::SSL)
if(WIN32)
Expand Down
4 changes: 2 additions & 2 deletions include/CppSockets/Address.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
** Project CppSockets, 2022
** Project LibCppSockets, 2022
**
** Author Francois Michaut
**
** Started on Sun Feb 13 17:09:05 2022 Francois Michaut
** Last update Sat Jun 20 09:12:58 2026 Francois Michaut
** Last update Wed Jul 1 14:19:51 2026 Francois Michaut
**
** Address.hpp : Interface to represent network addresses
*/
Expand Down
4 changes: 2 additions & 2 deletions include/CppSockets/IPv4.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
** Project CppSockets, 2022
** Project LibCppSockets, 2022
**
** Author Francois Michaut
**
** Started on Sun Feb 13 17:05:02 2022 Francois Michaut
** Last update Wed Aug 20 12:57:35 2025 Francois Michaut
** Last update Wed Jul 1 14:19:39 2026 Francois Michaut
**
** IPv4.hpp : Class used to represent and manipulate IPv4 addresses
*/
Expand Down
18 changes: 9 additions & 9 deletions include/CppSockets/OSDetection.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/*
** Project CppSockets, 2023
** Project LibCppSockets, 2023
**
** Author Francois Michaut
**
** Started on Tue May 9 23:20:20 2023 Francois Michaut
** Last update Sun May 14 14:03:20 2023 Francois Michaut
** Last update Wed Jul 1 14:20:01 2026 Francois Michaut
**
** OSDetection.hpp : OS Detection macros
*/

#pragma once

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#define OS_WINDOWS
#define OS_WINDOWS 1
#elif defined (__APPLE__)
#define OS_UNIX
#define OS_APPLE
#define OS_UNIX 1
#define OS_APPLE 1
#elif defined(__linux__)
#define OS_UNIX
#define OS_LINUX
#define OS_UNIX 1
#define OS_LINUX 1
#elif defined(__unix__)
#define OS_UNIX
#define OS_UNIX 1
#else
#error "Unknown compiler, please open a issue or pull request to support your compiler"
#error "Unknown OS, please open a issue or pull request to support your OS"
#endif
4 changes: 2 additions & 2 deletions include/CppSockets/Socket.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
** Project CppSockets, 2022
** Project LibCppSockets, 2022
**
** Author Francois Michaut
**
** Started on Sat Jan 15 01:17:42 2022 Francois Michaut
** Last update Wed Aug 20 14:01:21 2025 Francois Michaut
** Last update Wed Jul 1 14:20:12 2026 Francois Michaut
**
** Socket.hpp : Portable C++ socket class
*/
Expand Down
10 changes: 7 additions & 3 deletions include/CppSockets/Tls/Certificate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** Author Francois Michaut
**
** Started on Fri Aug 1 09:50:33 2025 Francois Michaut
** Last update Wed Aug 20 17:17:44 2025 Francois Michaut
** Last update Thu Jul 2 01:03:49 2026 Francois Michaut
**
** Certificate.hpp : Classes to create and manage Certificates
*/
Expand All @@ -27,6 +27,7 @@ namespace CppSockets {
x509Name();
x509Name(X509_NAME_ptr ptr);
x509Name(X509_NAME *ptr, bool own = true);
x509Name(const X509_NAME *ptr);

x509Name(const x509Name &other) { *this = other; }
x509Name(x509Name &&other) noexcept = default;
Expand Down Expand Up @@ -73,6 +74,7 @@ namespace CppSockets {
x509NameEntry();
x509NameEntry(X509_NAME_ENTRY_ptr ptr);
x509NameEntry(X509_NAME_ENTRY *ptr, bool own = true);
x509NameEntry(const X509_NAME_ENTRY *ptr);
x509NameEntry(const std::string &name, int type, const std::u8string &data);
x509NameEntry(const ASN1_OBJECT *obj, int type, const std::u8string &data);
x509NameEntry(int nid, int type, const std::u8string &data);
Expand Down Expand Up @@ -103,6 +105,7 @@ namespace CppSockets {
x509Extension();
x509Extension(X509_EXTENSION_ptr ptr);
x509Extension(X509_EXTENSION *ptr, bool own = true);
x509Extension(const X509_EXTENSION *ptr);
x509Extension(int nid, int crit, ASN1_OCTET_STRING *data);
x509Extension(const ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data);

Expand All @@ -119,8 +122,8 @@ namespace CppSockets {
void set_object(const ASN1_OBJECT *obj);
void set_critical(bool crit);

[[nodiscard]] auto get_data() const -> ASN1_OCTET_STRING *;
[[nodiscard]] auto get_object() const -> ASN1_OBJECT *;
[[nodiscard]] auto get_data() const -> const ASN1_OCTET_STRING *;
[[nodiscard]] auto get_object() const -> const ASN1_OBJECT *;
[[nodiscard]] auto get_critical() const -> bool;

[[nodiscard]] auto get() const -> X509_EXTENSION * { return m_ptr.get(); }
Expand All @@ -134,6 +137,7 @@ namespace CppSockets {
x509Certificate();
x509Certificate(X509_ptr ptr);
x509Certificate(X509 *ptr, bool own = true);
x509Certificate(const X509 *ptr);
explicit x509Certificate(const std::filesystem::path &pem_file_path);

x509Certificate(const x509Certificate &other) { *this = other; }
Expand Down
2 changes: 1 addition & 1 deletion include/CppSockets/Tls/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** Author Francois Michaut
**
** Started on Wed Aug 20 14:13:44 2025 Francois Michaut
** Last update Fri Aug 22 21:43:02 2025 Francois Michaut
** Last update Tue Jun 30 08:19:16 2026 Francois Michaut
**
** Context.hpp : Context for TLS sockets
*/
Expand Down
3 changes: 2 additions & 1 deletion include/CppSockets/Tls/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** Author Francois Michaut
**
** Started on Fri Aug 1 09:54:53 2025 Francois Michaut
** Last update Wed Aug 20 16:49:57 2025 Francois Michaut
** Last update Wed Jul 1 19:48:56 2026 Francois Michaut
**
** Utils.hpp : Tls Utility types
*/
Expand Down Expand Up @@ -58,4 +58,5 @@ namespace CppSockets {

// Don't leak macros
#undef CPP_SOCKETS_TLS_UTILS_DEFINE_DTOR
#undef CPP_SOCKETS_TLS_UTILS_DEFINE_PTR_CMD_PREFIX
#undef CPP_SOCKETS_TLS_UTILS_DEFINE_PTR
4 changes: 2 additions & 2 deletions include/CppSockets/Version.hpp.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
** Project CppSockets, 2022
** Project LibCppSockets, 2022
**
** Author Francois Michaut
**
** Started on Sun Aug 28 19:32:30 2022 Francois Michaut
** Last update Wed Sep 14 22:26:40 2022 Francois Michaut
** Last update Wed Jul 1 14:19:47 2026 Francois Michaut
**
** Version.hpp.in : Library version
*/
Expand Down
28 changes: 28 additions & 0 deletions include/CppSockets/internal/DLLExport.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
** Project LibCppSockets, 2026
**
** Author Francois Michaut
**
** Started on Wed Jul 1 12:30:17 2026 Francois Michaut
** Last update Wed Jul 1 18:54:43 2026 Francois Michaut
**
** DLLExport.hpp : Macros for DLL symbol exporting
*/

#pragma once

#include "CppSockets/OSDetection.hpp"

// TODO: Use theses to export only external symbols and avoid just exporting everything
#if OS_WINDOWS
#ifdef CPPSOCKETS_DLL_EXPORTS
// For windows, force the symbol to be exported when building the DLL
#define CPPSOCKETS_DLL_EXPORT __declspec(dllexport)
#else
// For windows, allows client code to know that the symbol must be loaded from the DLL
#define CPPSOCKETS_DLL_EXPORT __declspec(dllimport)
#endif
#else
// For Linux/MacOs force the symbol to be exported
#define CPPSOCKETS_DLL_EXPORT __attribute__ ((visibility("default")))
#endif
20 changes: 13 additions & 7 deletions include/CppSockets/internal/SocketInit.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
/*
** Project CppSockets, 2022
** Project LibCppSockets, 2022
**
** Author Francois Michaut
**
** Started on Sat Jan 15 01:17:42 2022 Francois Michaut
** Last update Wed Aug 20 13:04:47 2025 Francois Michaut
** Last update Wed Jul 1 14:20:05 2026 Francois Michaut
**
** SocketInit.hpp : Socket class automatic initialization and teardown
*/

// Inspired from https://stackoverflow.com/questions/64753466/how-do-i-automatically-implicitly-create-a-instance-of-a-class-at-program-launch/64754436#64754436

#pragma once

namespace CppSockets {
class SocketInit {
struct Cleanup {
~Cleanup();
};
public:
SocketInit();

private:
struct Cleanup {
~Cleanup();
};

static bool init;
static Cleanup cleanup;
static const bool init;
static const Cleanup cleanup;
};
}
Loading
Loading