-
Notifications
You must be signed in to change notification settings - Fork 7
Add kqueue context #22
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
base: main
Are you sure you want to change the base?
Changes from all commits
9609861
ff45cad
e47bd38
830c966
f88f85e
bd2bb46
9b3bbe2
2a2bb54
448da9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,10 @@ | |
| # cmake-format: on | ||
|
|
||
| cmake_minimum_required(VERSION 3.23) | ||
| project(beman_net VERSION 0.0.0 LANGUAGES CXX) | ||
| project( | ||
| beman_net | ||
| VERSION 0.0.0 | ||
| LANGUAGES CXX) | ||
| set(TARGET_NAME net) | ||
| set(TARGET_PREFIX beman.${TARGET_NAME}) | ||
| set(TARGET_LIBRARY beman_${TARGET_NAME}) | ||
|
|
@@ -13,13 +16,32 @@ set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}) | |
|
|
||
| set(CMAKE_CXX_STANDARD 23) | ||
|
|
||
| include(CheckIncludeFileCXX) | ||
| include(CheckCXXSourceCompiles) | ||
| check_include_file_cxx(sys/event.h NET_HAS_KQUEUE) | ||
| if(NET_HAS_KQUEUE) | ||
| add_compile_definitions(NET_HAS_KQUEUE) | ||
| check_cxx_source_compiles( | ||
| " | ||
| #include <sys/event.h> | ||
| #include <stdint.h> | ||
| int main() { | ||
| struct kevent ev{::uintptr_t(), ::int16_t(), EV_DELETE, ::uint32_t(), ::intptr_t(), nullptr, {}}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++ the |
||
| (void)ev; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if that should use |
||
| } | ||
| " | ||
| NET_KEVENT_HAS_EXT) | ||
| if(NET_KEVENT_HAS_EXT) | ||
| add_compile_definitions(NET_KEVENT_HAS_EXT) | ||
| endif() | ||
| endif() | ||
|
|
||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| execution | ||
| # for local development, use SOURCE_DIR <path-to>/execution | ||
| GIT_REPOSITORY https://github.com/bemanproject/execution | ||
| GIT_TAG e9c3032 | ||
| ) | ||
| execution | ||
| # for local development, use SOURCE_DIR <path-to>/execution | ||
| GIT_REPOSITORY https://github.com/bemanproject/execution | ||
| GIT_TAG 9cd2e66ba312c4396ac222868cc0486891cfa30b) | ||
| FetchContent_MakeAvailable(execution) | ||
|
|
||
| include(CTest) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,11 @@ | |
| #ifndef INCLUDED_BEMAN_NET_DETAIL_CONTAINER | ||
| #define INCLUDED_BEMAN_NET_DETAIL_CONTAINER | ||
|
|
||
| #include <algorithm> | ||
| #include <beman/net/detail/netfwd.hpp> | ||
| #include <cstddef> | ||
| #include <iterator> | ||
| #include <optional> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -28,6 +31,10 @@ class beman::net::detail::container { | |
| auto insert(Record r) -> ::beman::net::detail::socket_id; | ||
| auto erase(::beman::net::detail::socket_id id) -> void; | ||
| auto operator[](::beman::net::detail::socket_id id) -> Record&; | ||
| // using iterator = decltype(records)::iterator; | ||
| // auto begin() -> iterator; | ||
| // auto end() -> iterator; | ||
|
Comment on lines
+34
to
+36
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these declarations should either be included and appropriately defined or removed. |
||
| auto find(const Record& r) -> ::std::optional<::beman::net::detail::socket_id>; | ||
| }; | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
@@ -55,6 +62,19 @@ inline auto beman::net::detail::container<Record>::operator[](::beman::net::deta | |
| return ::std::get<1>(this->records[::std::size_t(id)]); | ||
| } | ||
|
|
||
| template <typename Record> | ||
| inline auto ::beman::net::detail::container<Record>::find(const Record& r) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This member function can be |
||
| -> ::std::optional<::beman::net::detail::socket_id> { | ||
| auto it = ::std::find_if(records.begin(), records.end(), [&](auto& l) { | ||
| return ::std::holds_alternative<Record>(l) && ::std::get<Record>(l) == r; | ||
| }); | ||
|
|
||
| if (it == records.end()) { | ||
| return {}; | ||
| } | ||
| return {::beman::net::detail::socket_id(::std::distance(records.begin(), it))}; | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,16 +6,17 @@ | |
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #if defined(NET_HAS_KQUEUE) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the header guards against being unavailable itself, i.e., this guard isn’t strictly necessary. |
||
| #include <beman/net/detail/kqueue_context.hpp> | ||
| #endif | ||
| #include <beman/net/detail/netfwd.hpp> | ||
| #include <beman/net/detail/context_base.hpp> | ||
| #include <beman/net/detail/io_context_scheduler.hpp> | ||
| #include <beman/net/detail/poll_context.hpp> | ||
| #include <beman/net/detail/container.hpp> | ||
| #include <cstdint> | ||
| #include <sys/socket.h> | ||
| #include <unistd.h> | ||
| #include <poll.h> | ||
| #include <limits> | ||
| #include <cerrno> | ||
| #include <csignal> | ||
|
|
||
|
|
@@ -29,8 +30,12 @@ class io_context; | |
|
|
||
| class beman::net::io_context { | ||
| private: | ||
| #if defined(NET_HAS_KQUEUE) | ||
| ::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::kqueue_context()}; | ||
| #else | ||
| ::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::poll_context()}; | ||
| ::beman::net::detail::context_base& d_context{*this->d_owned}; | ||
| #endif | ||
| ::beman::net::detail::context_base& d_context{*this->d_owned}; | ||
dietmarkuehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public: | ||
| using scheduler_type = ::beman::net::detail::io_context_scheduler; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
nullptrthe test is strictly C++: I’d use<cstdint>and::std::-qualify the respective names.