Skip to content

Commit 534f963

Browse files
committed
Architecture cleanup: header relocation, naming, docs, and formatting
Enforce layer boundaries by relocating platform-dependent headers out of the type-erased detail/ scope. Standardize naming across the native layer, fix stale documentation, and apply project-wide formatting. Header relocation: - Move endpoint_convert.hpp and make_err.hpp from detail/ to native/detail/ (both include platform headers, consumed only by native backends) - Rename io_buffer_param.hpp to buffer_param.hpp and move from io/ to detail/ (concrete value type, not an abstract base) - Remove buffer_param from the umbrella header (not user-facing) Naming and API consistency: - Rename impl_type/get_impl() to implementation_type/get() in all native headers to match the convention used at the abstract and concrete layers - Rename io_buffer_param.cpp test to buffer_param.cpp to match the renamed header - Pass std::stop_token and tls_context by const reference where only read (removes 8 unnecessary-value-param suppressions) Code quality: - Remove unused includes detected via clangd/clang-tidy - Fix clang-tidy diagnostics: suppress bugprone-unused-return-value on tls_context setup calls, fix widening conversions, add reserve() before emplace_back loops, add std::move for pass-by-value tls_context - Convert inline NOLINT to NOLINTNEXTLINE where the trailing comment caused clang-format to split lines - Fix stale "Defined in sockets.cpp" comments in op headers to reference actual service headers after header/source merges - Merge duplicate block comments in kqueue_socket_service.hpp and posix_signal_service.hpp - Move includes from posix_resolver.hpp to posix_resolver_service.hpp where they are used Design documentation: - Add "Implementation leaf nodes" subsection to the native layer section covering inheritance chains, leaf node table, common structural patterns, IOCP two-class split, and timer special case - Fix native layer code example to match actual implementation (template<auto Backend>, implementation_type/get() naming, backend_type trait aliases) - Add native_resolver to types table, fix backend tag and implementation header paths, update platform source layout Formatting: - Tune .clang-format: BinPackArguments false, AllowAllArgumentsOnNextLine false, AllowAllParametersOfDeclarationOnNextLine false, AlignConsecutiveAssignments false - Apply clang-format project-wide
1 parent e5a1b2a commit 534f963

81 files changed

Lines changed: 1111 additions & 950 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursor/rules/portable-headers.mdc

Lines changed: 38 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,81 @@
11
---
2-
description: No non-portable header includes in public headers
2+
description: No non-portable header includes in type-erased public headers
33
alwaysApply: false
44
---
55
# Portable Headers Rule
66

7-
**All headers in `include/boost/corosio/` (including all subdirectories) MUST NOT include platform-specific headers.**
7+
**Headers in `include/boost/corosio/` and `include/boost/corosio/detail/` MUST NOT include platform-specific headers.**
88

9-
## Scope
10-
11-
**Public headers**: ANY header file in `include/boost/corosio/` or any of its subdirectories.
9+
The `native/` subtree (`include/boost/corosio/native/`) is exempt — it is the direct/native API that deliberately exposes platform types.
1210

13-
Examples:
14-
- `include/boost/corosio/endpoint.hpp`
15-
- `include/boost/corosio/detail/config.hpp`
16-
- `include/boost/corosio/concept/...`
11+
## Scope
1712

18-
The entire `include/` tree is considered public API. This includes `detail/`, `concept/`, and any other subdirectories.
13+
**Type-erased headers** (platform includes FORBIDDEN):
14+
- `include/boost/corosio/*.hpp`
15+
- `include/boost/corosio/detail/*.hpp`
16+
- `include/boost/corosio/concept/*.hpp`
1917

20-
## Prohibited Headers
18+
**Native/direct headers** (platform includes ALLOWED):
19+
- `include/boost/corosio/native/*.hpp`
20+
- `include/boost/corosio/native/detail/**/*.hpp`
2121

22-
The following types of headers are **FORBIDDEN** in public headers:
22+
## Prohibited Headers (in type-erased scope)
2323

2424
### Windows-specific
25-
- `<windows.h>`
26-
- `<WinSock2.h>`
27-
- `<Ws2tcpip.h>`
28-
- `<MSWSock.h>`
25+
- `<windows.h>`, `<WinSock2.h>`, `<Ws2tcpip.h>`, `<MSWSock.h>`
2926
- Any other Windows SDK headers
3027

3128
### Unix/POSIX-specific
32-
- `<sys/socket.h>`
33-
- `<netinet/in.h>`
34-
- `<arpa/inet.h>`
35-
- `<unistd.h>`
36-
- `<sys/types.h>`
29+
- `<sys/socket.h>`, `<netinet/in.h>`, `<arpa/inet.h>`, `<unistd.h>`, `<sys/types.h>`
30+
- `<errno.h>` when used for platform-specific constants (e.g., `ECANCELED`)
3731
- Any other POSIX/Unix-specific headers
3832

3933
### Platform-specific macros and types
40-
- Any macros or types that require platform-specific headers
41-
- Platform-specific constants (e.g., `AF_INET`, `INADDR_ANY`)
34+
- Constants like `AF_INET`, `INADDR_ANY`, `ECANCELED`, `ERROR_OPERATION_ABORTED`
35+
- Types like `sockaddr_in`, `sockaddr_in6`, `sockaddr_storage`, `SOCKET`
4236

43-
## Allowed Locations
37+
## Allowed Locations for Platform-Specific Code
4438

45-
Platform-specific code is **ONLY** allowed in:
46-
47-
- Implementation files in `src/`
48-
- Platform abstraction layers in `src/`
39+
- `include/boost/corosio/native/` and `include/boost/corosio/native/detail/` (direct API)
40+
- Implementation files in `src/` (compilation firewall)
4941

5042
## Rationale
5143

52-
1. **Portability**: Public headers should compile on any platform without platform-specific dependencies
53-
2. **Maintainability**: Platform-specific code should be isolated in implementation files
54-
3. **User Experience**: Users should not be exposed to platform-specific types or headers
55-
4. **Clean API**: The public API should be platform-agnostic
44+
The library has two API layers:
45+
1. **Type-erased** (`corosio/` and `corosio/detail/`): portable, no platform headers leak to users
46+
2. **Native/direct** (`corosio/native/`): opt-in, exposes platform types for zero-overhead access
5647

5748
## Examples
5849

59-
### Bad (in public header)
50+
### Bad (platform header in type-erased scope)
6051
```cpp
61-
// include/boost/corosio/endpoint.hpp
62-
#ifdef _WIN32
63-
#include <WinSock2.h>
64-
#else
52+
// include/boost/corosio/detail/endpoint_convert.hpp ← WRONG location
53+
#include <sys/socket.h>
6554
#include <netinet/in.h>
66-
#endif
55+
```
6756

68-
class endpoint {
69-
sockaddr_in to_sockaddr_in() const; // Platform-specific type
70-
};
57+
### Good (platform header in native scope)
58+
```cpp
59+
// include/boost/corosio/native/detail/endpoint_convert.hpp ← correct
60+
#include <sys/socket.h>
61+
#include <netinet/in.h>
7162
```
7263

73-
### Good (in public header)
64+
### Good (type-erased public header)
7465
```cpp
7566
// include/boost/corosio/endpoint.hpp
76-
#include <boost/url/ipv4_address.hpp>
7767
#include <cstdint>
7868

7969
class endpoint {
80-
urls::ipv4_address v4_address() const noexcept;
70+
ipv4_address v4_address() const noexcept;
8171
std::uint16_t port() const noexcept;
8272
};
8373
```
8474

85-
### ✅ Good (in implementation file)
86-
```cpp
87-
// src/src/detail/endpoint_convert.hpp
88-
#ifdef _WIN32
89-
#include <WinSock2.h>
90-
#else
91-
#include <netinet/in.h>
92-
#endif
93-
94-
#include <boost/corosio/endpoint.hpp>
95-
96-
namespace boost {
97-
namespace corosio {
98-
namespace detail {
99-
100-
sockaddr_in to_sockaddr_in(endpoint const& ep) {
101-
// Platform-specific conversion logic
102-
}
103-
104-
} // namespace detail
105-
} // namespace corosio
106-
} // namespace boost
107-
```
108-
10975
## Enforcement
11076

111-
When adding or modifying public headers:
77+
When adding or modifying headers in the type-erased scope:
11278

113-
1. Check all `#include` directives
114-
2. Ensure no platform-specific headers are included
115-
3. Move any platform-specific code to `src/` implementation files
116-
4. Use platform abstraction utilities in `src/src/detail/` for conversions
79+
1. Check all `#include` directives for platform-specific headers
80+
2. If platform types are needed, the header belongs in `native/detail/`
81+
3. Type-erased code reaches platform APIs only through `src/` compiled translation units

doc/design/physical-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public:
106106
virtual std::coroutine_handle<> read_some(
107107
std::coroutine_handle<>,
108108
capy::executor_ref,
109-
io_buffer_param,
109+
buffer_param,
110110
std::stop_token,
111111
std::error_code*,
112112
std::size_t* ) = 0;

doc/modules/ROOT/pages/4.guide/4n.buffers.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ consuming.consume(n); // Advance by bytes read
160160

161161
This is used internally by `read()` and `write()` but can be used directly.
162162

163-
== io_buffer_param
163+
== buffer_param
164164

165-
The `io_buffer_param` class type-erases buffer sequences:
165+
The `buffer_param` class type-erases buffer sequences:
166166

167167
[source,cpp]
168168
----
169-
#include <boost/corosio/io_buffer_param.hpp>
169+
#include <boost/corosio/io/buffer_param.hpp>
170170
171-
void accept_any_buffer(corosio::io_buffer_param buffers)
171+
void accept_any_buffer(corosio::buffer_param buffers)
172172
{
173173
capy::mutable_buffer temp[8];
174174
std::size_t n = buffers.copy_to(temp, 8);

include/boost/corosio.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <boost/corosio/backend.hpp>
1414
#include <boost/corosio/cancel.hpp>
1515
#include <boost/corosio/endpoint.hpp>
16-
#include <boost/corosio/io_buffer_param.hpp>
1716
#include <boost/corosio/io_context.hpp>
1817
#include <boost/corosio/ipv4_address.hpp>
1918
#include <boost/corosio/ipv6_address.hpp>

include/boost/corosio/cancel.hpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,10 @@ namespace boost::corosio {
6363
6464
@see cancel_after
6565
*/
66-
auto cancel_at(
67-
capy::IoAwaitable auto&& op,
68-
timer& t,
69-
timer::time_point deadline)
66+
auto
67+
cancel_at(capy::IoAwaitable auto&& op, timer& t, timer::time_point deadline)
7068
{
71-
return detail::cancel_at_awaitable<
72-
std::decay_t<decltype(op)>, timer>(
69+
return detail::cancel_at_awaitable<std::decay_t<decltype(op)>, timer>(
7370
std::forward<decltype(op)>(op), t, deadline);
7471
}
7572

@@ -110,14 +107,11 @@ auto cancel_at(
110107
111108
@see cancel_at
112109
*/
113-
auto cancel_after(
114-
capy::IoAwaitable auto&& op,
115-
timer& t,
116-
timer::duration timeout)
110+
auto
111+
cancel_after(capy::IoAwaitable auto&& op, timer& t, timer::duration timeout)
117112
{
118113
return cancel_at(
119-
std::forward<decltype(op)>(op), t,
120-
timer::clock_type::now() + timeout);
114+
std::forward<decltype(op)>(op), t, timer::clock_type::now() + timeout);
121115
}
122116

123117
/** Cancel an operation if it does not complete by a deadline.
@@ -155,12 +149,10 @@ auto cancel_after(
155149
156150
@see cancel_after
157151
*/
158-
auto cancel_at(
159-
capy::IoAwaitable auto&& op,
160-
timer::time_point deadline)
152+
auto
153+
cancel_at(capy::IoAwaitable auto&& op, timer::time_point deadline)
161154
{
162-
return detail::cancel_at_awaitable<
163-
std::decay_t<decltype(op)>, timer, true>(
155+
return detail::cancel_at_awaitable<std::decay_t<decltype(op)>, timer, true>(
164156
std::forward<decltype(op)>(op), deadline);
165157
}
166158

@@ -198,13 +190,11 @@ auto cancel_at(
198190
199191
@see cancel_at
200192
*/
201-
auto cancel_after(
202-
capy::IoAwaitable auto&& op,
203-
timer::duration timeout)
193+
auto
194+
cancel_after(capy::IoAwaitable auto&& op, timer::duration timeout)
204195
{
205196
return cancel_at(
206-
std::forward<decltype(op)>(op),
207-
timer::clock_type::now() + timeout);
197+
std::forward<decltype(op)>(op), timer::clock_type::now() + timeout);
208198
}
209199

210200
} // namespace boost::corosio

include/boost/corosio/detail/acceptor_service.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ class BOOST_COROSIO_DECL acceptor_service
4747
*/
4848
virtual std::error_code open_acceptor_socket(
4949
tcp_acceptor::implementation& impl,
50-
int family, int type, int protocol) = 0;
50+
int family,
51+
int type,
52+
int protocol) = 0;
5153

5254
/** Bind an open acceptor to a local endpoint.
5355
5456
@param impl The acceptor implementation to bind.
5557
@param ep The local endpoint to bind to.
5658
@return Error code on failure, empty on success.
5759
*/
58-
virtual std::error_code bind_acceptor(
59-
tcp_acceptor::implementation& impl, endpoint ep) = 0;
60+
virtual std::error_code
61+
bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) = 0;
6062

6163
/** Start listening for incoming connections.
6264
@@ -67,8 +69,8 @@ class BOOST_COROSIO_DECL acceptor_service
6769
@param backlog The maximum length of the pending connection queue.
6870
@return Error code on failure, empty on success.
6971
*/
70-
virtual std::error_code listen_acceptor(
71-
tcp_acceptor::implementation& impl, int backlog) = 0;
72+
virtual std::error_code
73+
listen_acceptor(tcp_acceptor::implementation& impl, int backlog) = 0;
7274

7375
protected:
7476
/// Construct the acceptor service.

0 commit comments

Comments
 (0)