Skip to content
Closed
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: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build-*/
/bin64/
.cache/
/output/
/.temp
/.vscode/
/build/
!/build/Jamfile
!/build/wolfssl.jam
/out/
CMakeUserPresets.json
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,19 @@ file(GLOB_RECURSE BOOST_COROSIO_HEADERS CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/include/boost/corosio/*.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/boost/corosio.hpp")
file(GLOB_RECURSE BOOST_COROSIO_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
# Exclude wolfssl files from main library (they are added separately when WolfSSL is found)
list(FILTER BOOST_COROSIO_HEADERS EXCLUDE REGEX ".*/wolfssl/.*")
list(FILTER BOOST_COROSIO_SOURCES EXCLUDE REGEX ".*/wolfssl/.*")
"${CMAKE_CURRENT_SOURCE_DIR}/src/corosio/src/*.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/corosio/src/*.cpp")

source_group("" FILES "include/boost/corosio.hpp")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include/boost/corosio" PREFIX "include" FILES ${BOOST_COROSIO_HEADERS})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${BOOST_COROSIO_SOURCES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src/corosio/src" PREFIX "src" FILES ${BOOST_COROSIO_SOURCES})

function(boost_corosio_setup_properties target)
target_compile_features(${target} PUBLIC cxx_std_20)
target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}/src")
target_include_directories(${target} PRIVATE
"${PROJECT_SOURCE_DIR}/src/corosio"
"${PROJECT_SOURCE_DIR}/src/corosio/src")
target_link_libraries(${target}
PUBLIC
${BOOST_COROSIO_DEPENDENCIES}
Expand Down
16 changes: 16 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 8,
"configurePresets": [
{
"name": "Custom configure preset",
"displayName": "Custom configure preset",
"description": "Sets Ninja generator, build and install directory",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
}
}
]
}
12 changes: 4 additions & 8 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ project boost/corosio
: source-location $(COROSIO_ROOT)
;

local COROSIO_SRC =
[ glob $(COROSIO_ROOT)/src/*.cpp ]
[ glob $(COROSIO_ROOT)/src/detail/*.cpp ]
;

alias corosio_sources : $(COROSIO_SRC) ;

# System libraries
lib ws2_32 ;

alias corosio_sources : [ glob-tree-ex $(COROSIO_ROOT)/src/corosio/src : *.cpp ] ;

lib boost_corosio
: corosio_sources
: requirements
Expand All @@ -50,7 +45,8 @@ lib boost_corosio
<target-os>windows:<library>ws2_32
<target-os>windows:<define>_WIN32_WINNT=0x0602
<include>$(COROSIO_ROOT)/include
<include>$(COROSIO_ROOT)/src
<include>$(COROSIO_ROOT)/src/corosio
<include>$(COROSIO_ROOT)/src/corosio/src
: usage-requirements
<library>/boost/capy//boost_capy
<library>/boost/url//boost_url
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/io/acceptor.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ capy::task<void> accept_loop(corosio::io_context& ioc)

if (ec)
{
if (ec == boost::system::errc::operation_canceled)
if (ec == capy::cond::canceled)
break; // Acceptor was closed
std::cerr << "Accept error: " << ec.message() << "\n";
continue;
Expand Down
6 changes: 3 additions & 3 deletions doc/modules/ROOT/pages/io/sockets.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ auto [ec, n] = co_await s.read_some(

if (ec)
{
if (ec == capy::error::eof)
if (ec == capy::cond::eof)
std::cout << "Peer closed connection\n";
else
std::cerr << "Read error: " << ec.message() << "\n";
Expand Down Expand Up @@ -213,11 +213,11 @@ auto [ec, n] = co_await s.read_some(buf);

if (ec)
{
if (ec == capy::error::eof)
if (ec == capy::cond::eof)
{
// Normal disconnect (end of stream)
}
else if (ec == boost::system::errc::operation_canceled)
else if (ec == capy::cond::canceled)
{
// We called cancel()
}
Expand Down
4 changes: 3 additions & 1 deletion include/boost/corosio/acceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ class BOOST_COROSIO_DECL acceptor : public io_object
@return An awaitable that completes with `io_result<>`.
Returns success on successful accept, or an error code on
failure including:
- operation_canceled: Cancelled via stop_token or cancel()
- operation_canceled: Cancelled via stop_token or cancel().
Check `ec == cond::canceled` for portable comparison.

@par Preconditions
The acceptor must be listening (`is_open() == true`).
Expand All @@ -259,6 +260,7 @@ class BOOST_COROSIO_DECL acceptor : public io_object
/** Cancel any pending asynchronous operations.

All outstanding operations complete with `errc::operation_canceled`.
Check `ec == cond::canceled` for portable comparison.
*/
void cancel();

Expand Down
9 changes: 6 additions & 3 deletions include/boost/corosio/io_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class BOOST_COROSIO_DECL io_stream : public io_object
@return An awaitable that completes with a pair of
`{error_code, bytes_transferred}`. Returns success with the
number of bytes read, or an error code on failure including:
- capy::error::eof: End of stream reached
- operation_canceled: Cancelled via stop_token or cancel()
- capy::error::eof: End of stream reached.
Check `ec == cond::eof` for portable comparison.
- operation_canceled: Cancelled via stop_token or cancel().
Check `ec == cond::canceled` for portable comparison.

@par Preconditions
The socket must be open and connected.
Expand Down Expand Up @@ -75,7 +77,8 @@ class BOOST_COROSIO_DECL io_stream : public io_object
`{error_code, bytes_transferred}`. Returns success with the
number of bytes written, or an error code on failure including:
- broken_pipe: Connection closed by peer
- operation_canceled: Cancelled via stop_token or cancel()
- operation_canceled: Cancelled via stop_token or cancel().
Check `ec == cond::canceled` for portable comparison.

@par Preconditions
The socket must be open and connected.
Expand Down
1 change: 1 addition & 0 deletions include/boost/corosio/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class BOOST_COROSIO_DECL resolver : public io_object
/** Cancel any pending asynchronous operations.

All outstanding operations complete with `errc::operation_canceled`.
Check `ec == cond::canceled` for portable comparison.
*/
void cancel();

Expand Down
4 changes: 3 additions & 1 deletion include/boost/corosio/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ class BOOST_COROSIO_DECL socket : public io_stream
- connection_refused: No server listening at endpoint
- timed_out: Connection attempt timed out
- network_unreachable: No route to host
- operation_canceled: Cancelled via stop_token or cancel()
- operation_canceled: Cancelled via stop_token or cancel().
Check `ec == cond::canceled` for portable comparison.

@par Preconditions
The socket must be open (`is_open() == true`).
Expand All @@ -265,6 +266,7 @@ class BOOST_COROSIO_DECL socket : public io_stream
/** Cancel any pending asynchronous operations.

All outstanding operations complete with `errc::operation_canceled`.
Check `ec == cond::canceled` for portable comparison.
*/
void cancel();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,60 @@ operator()()
d(h).resume();
}

void
accept_op::
do_cancel() noexcept
{
if (listen_socket != INVALID_SOCKET)
{
::CancelIoEx(
reinterpret_cast<HANDLE>(listen_socket),
this);
}
}

void
read_op::
do_cancel() noexcept
{
if (impl.is_open())
{
::CancelIoEx(
reinterpret_cast<HANDLE>(impl.native_handle()),
this);
}
}

void
write_op::
do_cancel() noexcept
{
if (impl.is_open())
{
::CancelIoEx(
reinterpret_cast<HANDLE>(impl.native_handle()),
this);
}
}

void
connect_op::
do_cancel() noexcept
{
if (impl.is_open())
{
::CancelIoEx(
reinterpret_cast<HANDLE>(impl.native_handle()),
this);
}
}

win_socket_impl::
win_socket_impl(win_iocp_sockets& svc) noexcept
: svc_(svc)
, conn_(*this)
, rd_(*this)
, wr_(*this)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class win_acceptor_impl;
/** Connect operation state. */
struct connect_op : overlapped_op
{
win_socket_impl& impl;

explicit connect_op(win_socket_impl& impl_) noexcept : impl(impl_) {}

void do_cancel() noexcept override;
};

/** Read operation state with buffer descriptors. */
Expand All @@ -49,8 +54,12 @@ struct read_op : overlapped_op
WSABUF wsabufs[max_buffers];
DWORD wsabuf_count = 0;
DWORD flags = 0;
win_socket_impl& impl;

explicit read_op(win_socket_impl& impl_) noexcept : impl(impl_) {}

bool is_read_operation() const noexcept override { return true; }
void do_cancel() noexcept override;
};

/** Write operation state with buffer descriptors. */
Expand All @@ -59,6 +68,11 @@ struct write_op : overlapped_op
static constexpr std::size_t max_buffers = 16;
WSABUF wsabufs[max_buffers];
DWORD wsabuf_count = 0;
win_socket_impl& impl;

explicit write_op(win_socket_impl& impl_) noexcept : impl(impl_) {}

void do_cancel() noexcept override;
};

/** Accept operation state. */
Expand All @@ -73,6 +87,9 @@ struct accept_op : overlapped_op

/** Resume the coroutine after accept completes. */
void operator()() override;

/** Cancel the pending accept via CancelIoEx. */
void do_cancel() noexcept override;
};

//------------------------------------------------------------------------------
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ struct overlapped_op
struct canceller
{
overlapped_op* op;
void operator()() const noexcept { op->request_cancel(); }
void operator()() const noexcept
{
op->request_cancel();
op->do_cancel();
}
};

capy::any_coro h;
Expand Down Expand Up @@ -108,6 +112,11 @@ struct overlapped_op
cancelled.store(true, std::memory_order_release);
}

/** Hook for derived classes to perform actual I/O cancellation. */
virtual void do_cancel() noexcept
{
}

void start(std::stop_token token)
{
cancelled.store(false, std::memory_order_release);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading