Skip to content

Commit e4b6a8d

Browse files
committed
feat: coroutine types
1 parent e5dcfc0 commit e4b6a8d

File tree

9 files changed

+175
-63
lines changed

9 files changed

+175
-63
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,13 @@ jobs:
864864
with:
865865
path: buffers-root
866866

867+
- name: Clone Boost.Capy
868+
uses: actions/checkout@v3
869+
with:
870+
path: capy-root
871+
repository: cppalliance/capy
872+
ref: develop
873+
867874
- name: Setup C++
868875
uses: alandefreitas/cpp-actions/setup-cpp@v1.9.0
869876
id: setup-cpp
@@ -888,8 +895,12 @@ jobs:
888895
branch: ${{ (github.ref_name == 'master' && github.ref_name) || 'develop' }}
889896
boost-dir: boost-source
890897
modules-exclude-paths: ''
891-
scan-modules-dir: buffers-root
892-
scan-modules-ignore: buffers
898+
scan-modules-dir: |
899+
buffers-root
900+
capy-root
901+
scan-modules-ignore: |
902+
buffers
903+
capy
893904
894905
- name: Patch Boost
895906
id: patch
@@ -922,6 +933,7 @@ jobs:
922933
923934
# Patch boost-root with workspace module
924935
cp -r "$workspace_root"/buffers-root "libs/$module"
936+
cp -r "$workspace_root"/capy-root libs/capy
925937
926938
- name: Boost B2 Workflow
927939
uses: alandefreitas/cpp-actions/b2-workflow@v1.9.0

.github/workflows/claude.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use
5555
# The boost super-project requires one explicit dependency per-line.
5656
set(BOOST_BUFFERS_DEPENDENCIES
5757
Boost::assert
58+
Boost::capy
5859
Boost::config
5960
Boost::core
6061
Boost::system

build/Jamfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ explicit buffers_sources ;
4141
lib boost_buffers
4242
: buffers_sources
4343
: requirements
44+
<library>/boost//system
45+
<library>/boost//capy
46+
<include>../
4447
: usage-requirements
48+
<library>/boost//system
49+
<library>/boost//capy
4550
;
4651

4752
boost-install boost_buffers ;

include/boost/buffers.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#include <boost/buffers/any_buffers.hpp>
1414
#include <boost/buffers/any_read_source.hpp>
15+
#include <boost/buffers/any_sink.hpp>
1516
#include <boost/buffers/any_source.hpp>
17+
#include <boost/buffers/any_stream.hpp>
1618
#include <boost/buffers/buffer.hpp>
1719
#include <boost/buffers/buffer_pair.hpp>
1820
#include <boost/buffers/circular_buffer.hpp>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// Official repository: https://github.com/cppalliance/capy
8+
//
9+
10+
#ifndef BOOST_BUFFERS_ANY_STREAM_HPP
11+
#define BOOST_BUFFERS_ANY_STREAM_HPP
12+
13+
#include <boost/buffers/detail/config.hpp>
14+
15+
#ifdef BOOST_BUFFERS_HAS_CORO
16+
17+
#include <boost/buffers/buffer.hpp>
18+
#include <boost/capy/async_result.hpp>
19+
#include <boost/system/error_code.hpp>
20+
#include <cstdint>
21+
#include <memory>
22+
23+
namespace boost {
24+
namespace buffers {
25+
26+
/** Result of an asynchronous I/O operation.
27+
*/
28+
struct io_result
29+
{
30+
/** The error code, if any occurred.
31+
*/
32+
system::error_code ec;
33+
34+
/** Number of bytes transferred.
35+
*/
36+
std::size_t bytes_transferred;
37+
};
38+
39+
/** Asynchronous result type for I/O operations.
40+
*/
41+
using async_io_result = capy::async_result<io_result>;
42+
43+
class any_stream
44+
{
45+
public:
46+
struct impl
47+
{
48+
virtual ~impl() = default;
49+
50+
virtual auto read_some(
51+
buffers::mutable_buffer) ->
52+
async_io_result = 0;
53+
54+
virtual auto write_some(
55+
buffers::const_buffer) ->
56+
async_io_result = 0;
57+
};
58+
59+
/** Constructor
60+
@param p A pointer to the stream implementation.
61+
*/
62+
any_stream(
63+
std::shared_ptr<impl> p) noexcept
64+
: impl_(std::move(p))
65+
{
66+
}
67+
68+
/** Read some data into the buffer.
69+
70+
This coroutine reads some data into the buffer
71+
and returns the number of bytes read.
72+
73+
@param b The buffer to read into.
74+
@return The asynchronous result.
75+
*/
76+
auto read_some(
77+
buffers::mutable_buffer b) ->
78+
async_io_result
79+
{
80+
return impl_->read_some(b);
81+
}
82+
83+
/** Write some data from the buffer.
84+
This coroutine writes some data from the buffer
85+
and returns the number of bytes written.
86+
@param b The buffer to write from.
87+
@return The asynchronous result.
88+
*/
89+
auto write_some(
90+
buffers::const_buffer b) ->
91+
async_io_result
92+
{
93+
return impl_->write_some(b);
94+
}
95+
96+
private:
97+
std::shared_ptr<impl> impl_;
98+
};
99+
100+
} // buffers
101+
} // boost
102+
103+
#endif
104+
105+
#endif

include/boost/buffers/detail/config.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#include <boost/config.hpp>
1414

15+
#if __has_include(<version>)
16+
# include <version>
17+
#endif
18+
1519
namespace boost {
1620
namespace buffers {
1721

@@ -58,7 +62,15 @@ namespace buffers {
5862
return ::boost::system::error_code((ev), &loc ## __LINE__)
5963
#endif
6064

61-
//------------------------------------------------
65+
//-----------------------------------------------
66+
67+
#if defined(__cpp_lib_coroutine) && __cpp_lib_coroutine >= 201902L
68+
# define BOOST_BUFFERS_HAS_CORO 1
69+
#elif defined(__cpp_impl_coroutine) && __cpp_impl_coroutines >= 201902L
70+
# define BOOST_BUFFERS_HAS_CORO 1
71+
#endif
72+
73+
//-----------------------------------------------
6274

6375
// avoid all of Boost.TypeTraits for just this
6476
namespace detail {

test/cmake_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ else()
2222
# Primary dependencies
2323

2424
assert
25+
capy
2526
config
2627
core
2728
system

test/unit/any_stream.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// Official repository: https://github.com/cppalliance/beast2
8+
//
9+
10+
// Test that header file is self-contained.
11+
#include <boost/buffers/any_stream.hpp>
12+
13+
#ifdef BOOST_BUFFERS_HAS_CORO
14+
15+
#include "test_suite.hpp"
16+
17+
namespace boost {
18+
namespace buffers {
19+
20+
struct any_stream_test
21+
{
22+
void run()
23+
{
24+
}
25+
};
26+
27+
TEST_SUITE(
28+
any_stream_test,
29+
"boost.buffers.any_stream");
30+
31+
} // buffers
32+
} // boost
33+
34+
#endif

0 commit comments

Comments
 (0)