Skip to content

Commit 157512f

Browse files
authored
Merge pull request #38 from cbodley/wip-uring
add uring_context
2 parents fb254ef + 9043802 commit 157512f

File tree

7 files changed

+353
-5
lines changed

7 files changed

+353
-5
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ set(TARGET_LIBRARY beman_${TARGET_NAME})
1111
set(TARGET_ALIAS beman::${TARGET_NAME})
1212
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME})
1313

14+
option(BEMAN_NET_WITH_URING "Enable liburing io context" OFF)
15+
1416
include(FetchContent)
1517
FetchContent_Declare(
1618
execution

examples/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ set(xEXAMPLES taps)
2020
foreach(EXAMPLE ${EXAMPLES})
2121
set(EXAMPLE_TARGET ${TARGET_PREFIX}.examples.${EXAMPLE})
2222
add_executable(${EXAMPLE_TARGET})
23+
if(BEMAN_NET_WITH_URING)
24+
target_compile_definitions(
25+
${EXAMPLE_TARGET}
26+
PRIVATE BEMAN_NET_USE_URING
27+
)
28+
endif()
2329
target_sources(${EXAMPLE_TARGET} PRIVATE ${EXAMPLE}.cpp)
2430
target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${TARGET_LIBRARY})
2531
target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman::task)

examples/demo_task.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@ struct task {
184184
state->callback.reset();
185185
state->handle->stop_state = task::stop_state::stopping;
186186
state->handle->stop_source.request_stop();
187-
if (state->handle->stop_state == task::stop_state::stopped)
187+
if (state->handle->stop_state == task::stop_state::stopped) {
188188
this->object->handle->state->complete_stopped();
189+
} else {
190+
// transition back to running so sender_awaiter::stop() can safely complete later
191+
state->handle->stop_state = task::stop_state::running;
192+
}
189193
}
190194
};
191195
using stop_token = decltype(ex::get_stop_token(ex::get_env(::std::declval<Receiver>())));

include/beman/net/detail/io_context.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
#include <beman/net/detail/container.hpp>
1111
#include <beman/net/detail/context_base.hpp>
1212
#include <beman/net/detail/io_context_scheduler.hpp>
13+
#ifdef BEMAN_NET_USE_URING
14+
#include <beman/net/detail/uring_context.hpp>
15+
#else
1316
#include <beman/net/detail/poll_context.hpp>
17+
#endif
1418
#include <beman/net/detail/repeat_effect_until.hpp>
1519
#include <beman/execution/execution.hpp>
1620

1721
#include <cstdint>
1822
#include <sys/socket.h>
1923
#include <unistd.h>
20-
#include <poll.h>
2124
#include <cerrno>
2225
#include <csignal>
2326
#include <limits>
@@ -33,8 +36,12 @@ class io_context;
3336

3437
class beman::net::io_context {
3538
private:
39+
#ifdef BEMAN_NET_USE_URING
40+
::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::uring_context()};
41+
#else
3642
::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::poll_context()};
37-
::beman::net::detail::context_base& d_context{*this->d_owned};
43+
#endif
44+
::beman::net::detail::context_base& d_context{*this->d_owned};
3845

3946
public:
4047
using scheduler_type = ::beman::net::detail::io_context_scheduler;

include/beman/net/detail/sender.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ struct beman::net::detail::sender_state : Desc::operation, ::beman::net::detail:
113113
}
114114
}
115115
auto complete() -> void override final {
116-
d_callback.reset();
117116
if (0 == --this->d_outstanding) {
117+
d_callback.reset();
118118
this->d_data.set_value(*this, ::std::move(this->d_receiver));
119119
}
120120
}
121121
auto error(::std::error_code err) -> void override final {
122-
d_callback.reset();
123122
if (0 == --this->d_outstanding) {
123+
d_callback.reset();
124124
::beman::net::detail::ex::set_error(::std::move(this->d_receiver), std::move(err));
125125
}
126126
}

0 commit comments

Comments
 (0)