Skip to content

Commit effb752

Browse files
authored
Merge pull request #694 from calgray/main
- io_uring_context with non-TU local c++23 htons implementation - added gcc14 in C++23 mode to CI (clang still TODO, blocked by issue with gtest)
2 parents c6e5af9 + dc1cd41 commit effb752

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

.github/workflows/libunifex-ci.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ name: libunifex CI
33
# Trigger on pushes to all branches and for all pull-requests
44
on: [push, pull_request]
55

6-
env:
7-
CMAKE_VERSION: 3.16.2
8-
NINJA_VERSION: 1.9.0
9-
10-
116
jobs:
127
build:
138
name: ${{ matrix.config.name }}
149
runs-on: ${{ matrix.config.os }}
10+
env:
11+
CMAKE_VERSION: ${{ matrix.config.cmake_version || '3.16.2' }}
12+
NINJA_VERSION: ${{ matrix.config.ninja_version || '1.9.0' }}
1513
strategy:
1614
fail-fast: false
1715
matrix:
@@ -152,6 +150,33 @@ jobs:
152150
cc: "gcc-14", cxx: "g++-14",
153151
cmake_args: "-D CMAKE_CXX_STANDARD:STRING=20 -D CMAKE_CXX_FLAGS=-fno-exceptions"
154152
}
153+
- {
154+
name: "Linux GCC 14 Debug (C++23)", artifact: "Linux.tar.xz",
155+
os: ubuntu-24.04,
156+
io_sys: io_uring,
157+
build_type: Debug,
158+
cc: "gcc-14", cxx: "g++-14",
159+
cmake_version: "3.20.0",
160+
cmake_args: "-D CMAKE_CXX_STANDARD:STRING=23"
161+
}
162+
- {
163+
name: "Linux GCC 14 Optimised (C++23)", artifact: "Linux.tar.xz",
164+
os: ubuntu-24.04,
165+
io_sys: io_uring,
166+
build_type: RelWithDebInfo,
167+
cc: "gcc-14", cxx: "g++-14",
168+
cmake_version: "3.20.0",
169+
cmake_args: "-D CMAKE_CXX_STANDARD:STRING=23"
170+
}
171+
- {
172+
name: "Linux GCC 14 Optimised noexcept (C++23)", artifact: "Linux.tar.xz",
173+
os: ubuntu-24.04,
174+
io_sys: io_uring,
175+
build_type: RelWithDebInfo,
176+
cc: "gcc-14", cxx: "g++-14",
177+
cmake_version: "3.20.0",
178+
cmake_args: "-D CMAKE_CXX_STANDARD:STRING=23 -D CMAKE_CXX_FLAGS=-fno-exceptions"
179+
}
155180
- {
156181
name: "Linux Clang 15 Debug (C++17)", artifact: "Linux.tar.xz",
157182
os: ubuntu-22.04,
@@ -414,7 +439,11 @@ jobs:
414439
elseif ("${{ runner.os }}" STREQUAL "Linux")
415440
set(ninja_suffix "linux.zip")
416441
set(cmake_suffix "Linux-x86_64.tar.gz")
417-
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
442+
if(cmake_version VERSION_GREATER_EQUAL 3.20.0)
443+
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin")
444+
else()
445+
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
446+
endif()
418447
elseif ("${{ runner.os }}" STREQUAL "macOS")
419448
set(ninja_suffix "mac.zip")
420449
set(cmake_suffix "Darwin-x86_64.tar.gz")

include/unifex/linux/io_uring_context.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
# include <sys/socket.h>
5353
# include <sys/uio.h>
5454
# include <unistd.h>
55+
# if __has_include(<bit>)
56+
# include <bit>
57+
# endif // __has_include(<bit>)
5558

5659
# include <unifex/detail/prologue.hpp>
5760

@@ -1351,6 +1354,20 @@ class io_uring_context::accept_stream {
13511354
port_t port_;
13521355
safe_file_descriptor fd_;
13531356

1357+
# if __cpp_lib_byteswap >= 202110L
1358+
static constexpr std::uint16_t host_to_network(std::uint16_t value) {
1359+
return (
1360+
std::endian::native == std::endian::little
1361+
? std::byteswap(value)
1362+
: value
1363+
);
1364+
}
1365+
# else
1366+
static std::uint16_t host_to_network(std::uint16_t value) {
1367+
return htons(value);
1368+
}
1369+
# endif // __cpp_lib_byteswap
1370+
13541371
// TODO should this run on the io_context? If so, why?
13551372
void open_socket() noexcept {
13561373
// both IPv4 and IPv6
@@ -1365,7 +1382,7 @@ class io_uring_context::accept_stream {
13651382
UNIFEX_ASSERT(ret != -1);
13661383

13671384
addr.sin6_family = AF_INET6;
1368-
addr.sin6_port = htons(port_);
1385+
addr.sin6_port = host_to_network(port_);
13691386
addr.sin6_addr = in6addr_any;
13701387
ret = bind(fd_.get(), (const struct sockaddr*)&addr, sizeof(addr));
13711388
UNIFEX_ASSERT(ret != -1);
@@ -1379,4 +1396,4 @@ class io_uring_context::accept_stream {
13791396

13801397
# include <unifex/detail/epilogue.hpp>
13811398

1382-
#endif // __has_include(<liburing.h>)
1399+
#endif // UNIFEX_NO_LIBURING

0 commit comments

Comments
 (0)