Skip to content
Open
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set(TARGET_LIBRARY beman_${TARGET_NAME})
set(TARGET_ALIAS beman::${TARGET_NAME})
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME})

option(BEMAN_NET_WITH_URING "Enable liburing io context" OFF)

include(FetchContent)
FetchContent_Declare(
execution
Expand Down
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ set(xEXAMPLES taps)
foreach(EXAMPLE ${EXAMPLES})
set(EXAMPLE_TARGET ${TARGET_PREFIX}.examples.${EXAMPLE})
add_executable(${EXAMPLE_TARGET})
if(BEMAN_NET_WITH_URING)
target_compile_definitions(
${EXAMPLE_TARGET}
PRIVATE BEMAN_NET_USE_URING
)
endif()
target_sources(${EXAMPLE_TARGET} PRIVATE ${EXAMPLE}.cpp)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${TARGET_LIBRARY})
target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman::task)
Expand Down
6 changes: 5 additions & 1 deletion examples/demo_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ struct task {
state->callback.reset();
state->handle->stop_state = task::stop_state::stopping;
state->handle->stop_source.request_stop();
if (state->handle->stop_state == task::stop_state::stopped)
if (state->handle->stop_state == task::stop_state::stopped) {
this->object->handle->state->complete_stopped();
} else {
// transition back to running so sender_awaiter::stop() can safely complete later
state->handle->stop_state = task::stop_state::running;
}
}
};
using stop_token = decltype(ex::get_stop_token(ex::get_env(::std::declval<Receiver>())));
Expand Down
11 changes: 9 additions & 2 deletions include/beman/net/detail/io_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
#include <beman/net/detail/container.hpp>
#include <beman/net/detail/context_base.hpp>
#include <beman/net/detail/io_context_scheduler.hpp>
#ifdef BEMAN_NET_USE_URING
#include <beman/net/detail/uring_context.hpp>
#else
#include <beman/net/detail/poll_context.hpp>
#endif
#include <beman/net/detail/repeat_effect_until.hpp>
#include <beman/execution/execution.hpp>

#include <cstdint>
#include <sys/socket.h>
#include <unistd.h>
#include <poll.h>
#include <cerrno>
#include <csignal>
#include <limits>
Expand All @@ -33,8 +36,12 @@ class io_context;

class beman::net::io_context {
private:
#ifdef BEMAN_NET_USE_URING
::std::unique_ptr<::beman::net::detail::context_base> d_owned{new ::beman::net::detail::uring_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};

public:
using scheduler_type = ::beman::net::detail::io_context_scheduler;
Expand Down
4 changes: 2 additions & 2 deletions include/beman/net/detail/sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ struct beman::net::detail::sender_state : Desc::operation, ::beman::net::detail:
}
}
auto complete() -> void override final {
d_callback.reset();
if (0 == --this->d_outstanding) {
d_callback.reset();
this->d_data.set_value(*this, ::std::move(this->d_receiver));
}
}
auto error(::std::error_code err) -> void override final {
d_callback.reset();
if (0 == --this->d_outstanding) {
d_callback.reset();
::beman::net::detail::ex::set_error(::std::move(this->d_receiver), std::move(err));
}
}
Expand Down
Loading