Skip to content

Commit bb4c596

Browse files
committed
documentation and tidy up tls stream APIs
1 parent 9937fb8 commit bb4c596

10 files changed

Lines changed: 77 additions & 44 deletions

File tree

‎.cursor/rules/awaitable-ops.mdc‎

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

‎.cursor/rules/doc-awaitable.mdc‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: doc javadoc for async awaitable functions of I/O objects
3+
alwaysApply: false
4+
---
5+
6+
**Checklist for an outstanding awaitable function javadoc:**
7+
- **Brief** — One-sentence summary starting with a verb, e.g. "Read data from the stream asynchronously."
8+
- **Extended description** — Short paragraph explaining what the function does. State that it is an asynchronous operation that suspends the calling coroutine until completion. If composed, state which underlying operations it is implemented in terms of.
9+
- **Completion conditions** — Bulleted `@li` list of conditions under which the operation completes and the coroutine resumes (e.g. "The supplied buffers are full", "An error occurs", "The operation was canceled").
10+
- **Concurrency and overlap** — State which operations may be simultaneously in flight. E.g. for a read: "At most one write operation may be in flight concurrently with this read operation. No other read operations may be in flight until this operation completes." Clarify that simultaneous in-flight operations does *not* imply that the initiating calls themselves may be made concurrently; all calls to the stream must be made from the same implicit or explicit serialization context.
11+
- **`@param` for each parameter** — Including ownership/lifetime semantics. For buffers: state that the caller retains ownership and must guarantee validity until the operation completes. For string/view parameters: state whether the implementation copies the data or requires it to remain valid for the duration.
12+
- **`@return`** — Describe the returned aggregate and its elements. The first element is always `error_code`. Name and describe each subsequent element (e.g. "bytes_transferred", "endpoint"). Note that the result is customarily destructured by the caller.
13+
- **Error conditions** — Document the notable `error_code` values or conditions that may appear in the first element. E.g. `capy::cond::canceled` if the stop token was activated or the i/o object's `cancel()` was called, EOF conditions, protocol-specific errors, etc. State that error codes should be compared to error conditions, not specific values.
14+
- **`@throws`** — Typically only for precondition violations. State which preconditions trigger exceptions, or state that no exceptions are thrown during normal operation.
15+
- **Cancellation** — State that the operation supports cancellation via `stop_token` propagated through the IoAwaitable protocol, or via the i/o object's `cancel()` member. State that the resulting error compares equal to `capy::cond::canceled`.
16+
- **`@par Example`** — Two or three `@code` blocks showing different usage patterns: typical happy path with destructuring, error handling, cancellation, different overloads, etc.
17+
- **`@note` / `@par Remarks`** — Behavioral gotchas. E.g. "This operation may not read all of the requested bytes." Or equivalence to another overload.
18+
- **`@tparam`** — For non-variadic template parameters. State the concept requirement (e.g. "The type must satisfy the *AsyncStream* concept"). Don't document `Args...`.
19+
- **`@see`** — Always last. Cross-references to related functions, concepts, and relevant RFC sections.
20+
- Keep the ascii-art to a minimum, only add dividers if the class declaration is very long
21+
- Don't emit @tparam for deduced types or concepts

‎include/boost/corosio/io_stream.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class BOOST_COROSIO_DECL io_stream : public io_object
126126
template<capy::MutableBufferSequence MB>
127127
auto read_some(MB const& buffers)
128128
{
129-
return read_some_awaitable<MutableBufferSequence>(*this, buffers);
129+
return read_some_awaitable<MB>(*this, buffers);
130130
}
131131

132132
/** Asynchronously write data to the stream.
@@ -192,7 +192,7 @@ class BOOST_COROSIO_DECL io_stream : public io_object
192192
template<capy::ConstBufferSequence CB>
193193
auto write_some(CB const& buffers)
194194
{
195-
return write_some_awaitable<ConstBufferSequence>(*this, buffers);
195+
return write_some_awaitable<CB>(*this, buffers);
196196
}
197197

198198
protected:

‎include/boost/corosio/openssl_stream.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class BOOST_COROSIO_DECL openssl_stream final
136136
return stream_;
137137
}
138138

139+
std::string_view
140+
name() const noexcept override;
141+
139142
protected:
140143
capy::io_task<std::size_t>
141144
do_read_some(capy::some_mutable_buffers buffers) override;

‎include/boost/corosio/tls_stream.hpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/capy/io_task.hpp>
1818

1919
#include <cstddef>
20+
#include <string_view>
2021

2122
namespace boost::corosio {
2223

@@ -145,6 +146,13 @@ class BOOST_COROSIO_DECL tls_stream
145146
virtual capy::any_stream const&
146147
next_layer() const noexcept = 0;
147148

149+
/** Returns the name of the TLS backend.
150+
151+
@return A string identifying the TLS implementation,
152+
such as "openssl" or "wolfssl".
153+
*/
154+
virtual std::string_view name() const noexcept = 0;
155+
148156
protected:
149157
tls_stream() = default;
150158

‎include/boost/corosio/wolfssl_stream.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class BOOST_COROSIO_DECL wolfssl_stream final
136136
return stream_;
137137
}
138138

139+
std::string_view
140+
name() const noexcept override;
141+
139142
protected:
140143
capy::io_task<std::size_t>
141144
do_read_some(capy::some_mutable_buffers buffers) override;

‎src/openssl/src/openssl_stream.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,11 @@ shutdown()
735735
co_return co_await impl_->do_shutdown();
736736
}
737737

738+
std::string_view
739+
openssl_stream::
740+
name() const noexcept
741+
{
742+
return "openssl";
743+
}
744+
738745
} // namespace boost::corosio

‎src/wolfssl/src/wolfssl_stream.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,11 @@ shutdown()
953953
co_return co_await impl_->do_shutdown();
954954
}
955955

956+
std::string_view
957+
wolfssl_stream::
958+
name() const noexcept
959+
{
960+
return "wolfssl";
961+
}
962+
956963
} // namespace boost::corosio

‎test/unit/openssl_stream.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ struct openssl_stream_test
4646
test::context_mode::separate_cert
4747
};
4848

49+
void testName()
50+
{
51+
using namespace test;
52+
53+
io_context ioc;
54+
auto ctx = make_anon_context();
55+
tcp_socket sock( ioc );
56+
openssl_stream stream( &sock, ctx );
57+
58+
BOOST_TEST( stream.name() == "openssl" );
59+
}
60+
4961
/** Test certificate chain validation (OpenSSL-specific).
5062
5163
OpenSSL supports sending full certificate chains via
@@ -91,6 +103,7 @@ struct openssl_stream_test
91103
test::testMtls( make_stream );
92104

93105
testCertificateChain();
106+
testName();
94107
}
95108
};
96109

‎test/unit/wolfssl_stream.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ struct wolfssl_stream_test
4646
test::context_mode::separate_cert
4747
};
4848

49+
void testName()
50+
{
51+
using namespace test;
52+
53+
io_context ioc;
54+
auto ctx = make_client_context();
55+
tcp_socket sock( ioc );
56+
wolfssl_stream stream( &sock, ctx );
57+
58+
BOOST_TEST( stream.name() == "wolfssl" );
59+
}
60+
4961
/** Test certificate chain validation (WolfSSL-specific).
5062
5163
WolfSSL has limited certificate chain support compared to OpenSSL.
@@ -98,6 +110,7 @@ struct wolfssl_stream_test
98110
test::testMtls( make_stream );
99111

100112
testCertificateChain();
113+
testName();
101114
}
102115
};
103116

0 commit comments

Comments
 (0)