Skip to content

Improve backwards compatibility #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2023
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
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if(HUNTER_ENABLED)
# Workaround hunter hideing system libs
set(HUNTER_LIBPATH $ENV{PKG_CONFIG_LIBDIR})
unset(ENV{PKG_CONFIG_LIBDIR})
pkg_search_module(URING REQUIRED NO_CMAKE_PATH liburing>=2.3 uring>=2.3)
pkg_search_module(URING REQUIRED NO_CMAKE_PATH liburing uring)
set(ENV{PKG_CONFIG_LIBDIR} ${HUNTER_LIBPATH})
else()
pkg_search_module(URING REQUIRED NO_CMAKE_PATH liburing>=2.3 uring>=2.3)
pkg_search_module(URING REQUIRED NO_CMAKE_PATH liburing uring)
endif()

option(ASYNCPP_BUILD_TEST "Enable test builds" ON)
Expand All @@ -26,12 +26,19 @@ else()
include(cmake/Fetch_asyncpp.cmake)
endif()

try_run(OP_LAST OP_LAST_COMPILE_RESULT SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/detect-max-op.c)

add_library(asyncpp_uring INTERFACE)
target_link_libraries(asyncpp_uring INTERFACE asyncpp Threads::Threads
${URING_LIBRARIES})
target_include_directories(asyncpp_uring
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(asyncpp_uring INTERFACE cxx_std_20)
if(OP_LAST_COMPILE_RESULT)
target_compile_definitions(asyncpp_uring
INTERFACE ASYNCPP_URING_OP_LAST=${OP_LAST})
endif()

if(ASYNCPP_BUILD_TEST)
enable_testing()
Expand Down
3 changes: 3 additions & 0 deletions cmake/detect-max-op.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <liburing.h>

int main() { return IORING_OP_LAST - 1; }
6 changes: 5 additions & 1 deletion examples/echo-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ int main() {
io_service io{p};
buffer_group buffers{io, 32 * 1024, 32};
io.launch([](io_service& io, buffer_group& buffers) -> task<> {
// Try create a socket and fallback to sync if unsupported
// Try create a socket and fallback to sync if unsupported
#if ASYNCPP_URING_OP_LAST >= 45
int sock = io.has_capability(IORING_OP_SOCKET) //
? co_await io.socket(AF_INET, SOCK_STREAM, 0, 0) //
: socket(AF_INET, SOCK_STREAM, 0);
#else
int sock = socket(AF_INET, SOCK_STREAM, 0);
#endif
if (sock < 0) {
std::cout << "failed to create socket: " << strerror(-sock) << std::endl;
co_return;
Expand Down
6 changes: 5 additions & 1 deletion examples/echo-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ int main() {
}(io, exit));
buffer_group buffers{io, 32 * 1024, 32};
io.launch([](io_service& io, buffer_group& buffers, std::stop_source& exit) -> task<> {
// Try create a socket and fallback to sync if unsupported
// Try create a socket and fallback to sync if unsupported
#if ASYNCPP_URING_OP_LAST >= 45
int sock = io.has_capability(IORING_OP_SOCKET) //
? co_await io.socket(AF_INET, SOCK_STREAM, 0, 0) //
: socket(AF_INET, SOCK_STREAM, 0);
#else
int sock = socket(AF_INET, SOCK_STREAM, 0);
#endif
if (sock < 0) {
std::cout << "failed to create socket: " << strerror(-sock) << std::endl;
co_return;
Expand Down
4 changes: 3 additions & 1 deletion include/asyncpp/uring/capability_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace asyncpp::uring {

public:
constexpr static struct {
} no_parse_tag;
} no_parse_tag{};
capability_set(struct io_uring* ring) : m_supported{} { this->parse(ring); }
capability_set() : m_supported{} { this->parse(nullptr); }
constexpr capability_set(decltype(no_parse_tag)) noexcept : m_supported{} {}
Expand Down Expand Up @@ -115,6 +115,8 @@ namespace asyncpp::uring {
"GETXATTR",
"SOCKET",
"URING_CMD",
"SEND_ZC",
"SENDMSG_ZC",
};

if (index >= (sizeof(names) / sizeof(names[0]))) return "";
Expand Down
2 changes: 2 additions & 0 deletions include/asyncpp/uring/index_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace asyncpp::uring {
~bit_storage() noexcept { clear(); }

bit_storage(const bit_storage& other) : m_allocator{other.m_allocator} {
memset(&m_data, 0, sizeof(m_data));
m_data.inplace.size = 0x80;
resize_bits(other.bit_size());
memcpy(data(), other.data(), std::min(byte_size(), other.byte_size()));
}
Expand Down
Loading