Skip to content

Commit 5789a7f

Browse files
ashtumvinniefalco
authored andcommitted
feat: more implementation
1 parent 7437cf1 commit 5789a7f

File tree

12 files changed

+896
-9
lines changed

12 files changed

+896
-9
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,13 @@ jobs:
827827
with:
828828
path: ws-io-root
829829

830+
- name: Clone Boost.Http.Io
831+
uses: actions/checkout@v3
832+
with:
833+
repository: cppalliance/http_io
834+
path: http-io-root
835+
ref: develop
836+
830837
- name: Clone Boost.Ws.Proto
831838
uses: actions/checkout@v3
832839
with:
@@ -884,12 +891,14 @@ jobs:
884891
modules-exclude-paths: ''
885892
scan-modules-dir: |
886893
ws-io-root
894+
http-io-root
887895
ws-proto-root
888896
http-proto-root
889897
buffers-root
890898
rts-root
891899
scan-modules-ignore: |
892900
ws_io
901+
http_io
893902
ws_proto
894903
http_proto
895904
buffers
@@ -961,11 +970,12 @@ jobs:
961970
echo -E "boost_root=$boost_root" >> $GITHUB_OUTPUT
962971
963972
# Patch boost-root with workspace module
964-
cp -r "$workspace_root"/ws-io-root "libs/$module"
965973
cp -r "$workspace_root"/rts-root libs/rts
966974
cp -r "$workspace_root"/buffers-root libs/buffers
967975
cp -r "$workspace_root"/http-proto-root libs/http_proto
976+
cp -r "$workspace_root"/http-io-root libs/http_io
968977
cp -r "$workspace_root"/ws-proto-root libs/ws_proto
978+
cp -r "$workspace_root"/ws-io-root "libs/$module"
969979
970980
- name: Boost B2 Workflow
971981
uses: alandefreitas/cpp-actions/[email protected]
@@ -1179,6 +1189,13 @@ jobs:
11791189
with:
11801190
path: ws-io-root
11811191

1192+
- name: Clone Boost.Http.Io
1193+
uses: actions/checkout@v3
1194+
with:
1195+
repository: cppalliance/http_io
1196+
path: http-io-root
1197+
ref: develop
1198+
11821199
- name: Clone Boost.WS.Proto
11831200
uses: actions/checkout@v3
11841201
with:
@@ -1217,12 +1234,14 @@ jobs:
12171234
modules-exclude-paths: ''
12181235
scan-modules-dir: |
12191236
ws-io-root
1237+
http-io-root
12201238
ws-proto-root
12211239
http-proto-root
12221240
buffers-root
12231241
rts-root
12241242
scan-modules-ignore: |
12251243
ws_io
1244+
http_io
12261245
ws_proto
12271246
http_proto
12281247
buffers
@@ -1258,10 +1277,11 @@ jobs:
12581277
echo -E "boost_root=$boost_root" >> $GITHUB_OUTPUT
12591278
12601279
# Patch boost-root with workspace module
1261-
cp -r "$workspace_root"/ws-io-root "libs/$module"
12621280
cp -r "$workspace_root"/rts-root libs/rts
12631281
cp -r "$workspace_root"/buffers-root libs/buffers
1282+
cp -r "$workspace_root"/http-io-root libs/http_io
12641283
cp -r "$workspace_root"/http-proto-root libs/http_proto
1284+
cp -r "$workspace_root"/ws-io-root "libs/$module"
12651285
cp -r "$workspace_root"/ws-proto-root libs/ws_proto
12661286
12671287
- uses: actions/setup-node@v4

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ set(BOOST_WS_IO_DEPENDENCIES
6060
Boost::system
6161
Boost::url
6262
Boost::ws_proto
63+
Boost::http_io
6364
)
6465

6566
foreach (BOOST_WS_IO_DEPENDENCY ${BOOST_WS_IO_DEPENDENCIES})
@@ -131,13 +132,15 @@ endif ()
131132
#-------------------------------------------------
132133
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
133134

134-
file(GLOB_RECURSE BOOST_WS_IO_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp include/boost/*.natvis)
135+
file(GLOB_RECURSE BOOST_WS_IO_HEADERS CONFIGURE_DEPENDS include/boost/ws_io/*.hpp include/boost/ws_io/*.natvis)
135136
file(GLOB_RECURSE BOOST_WS_IO_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp)
137+
file(GLOB_RECURSE BOOST_WS_PROTO_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp)
136138

137-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_WS_IO_HEADERS})
138-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "ws_io" FILES ${BOOST_WS_IO_SOURCES})
139+
source_group("" FILES "include/boost/ws_io.hpp" "build/Jamfile")
140+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/ws_io PREFIX "include" FILES ${BOOST_WS_IO_HEADERS})
141+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_WS_IO_SOURCES})
139142

140-
add_library(boost_ws_io ${BOOST_WS_IO_HEADERS} ${BOOST_WS_IO_SOURCES})
143+
add_library(boost_ws_io include/boost/ws_io.hpp build/Jamfile ${BOOST_WS_IO_HEADERS} ${BOOST_WS_IO_SOURCES})
141144
add_library(Boost::ws_io ALIAS boost_ws_io)
142145
target_compile_features(boost_ws_io PUBLIC cxx_constexpr)
143146
target_include_directories(boost_ws_io PUBLIC "${PROJECT_SOURCE_DIR}/include")

build/Jamfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ lib boost_ws_io
4343
: ws_io_sources
4444
: requirements
4545
<library>/boost//ws_proto
46+
<library>/boost//http_io
4647
: usage-requirements
4748
<library>/boost//ws_proto
49+
<library>/boost//http_io
4850
;
4951

5052
boost-install boost_ws_io ;

include/boost/ws_io/client.hpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//
2+
// Copyright (c) 2025 Vinnie Falco ([email protected])
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/ws_io
8+
//
9+
10+
#ifndef BOOST_WS_IO_CLIENT_HPP
11+
#define BOOST_WS_IO_CLIENT_HPP
12+
13+
#include <boost/ws_io/detail/config.hpp>
14+
#include <boost/ws_proto/client.hpp>
15+
#include <boost/rts/context_fwd.hpp>
16+
#include <boost/http_proto/response_view.hpp>
17+
#include <boost/http_proto/request.hpp>
18+
#include <boost/asio/async_result.hpp>
19+
#include <boost/asio/default_completion_token.hpp>
20+
#include <boost/buffers/const_buffer.hpp>
21+
#include <boost/core/detail/string_view.hpp>
22+
#include <boost/core/span.hpp>
23+
#include <type_traits>
24+
25+
namespace boost {
26+
namespace ws_io {
27+
28+
struct null_decorator
29+
{
30+
void operator()(...) const noexcept
31+
{
32+
}
33+
};
34+
35+
struct frame
36+
{
37+
ws_proto::frame_type kind;
38+
buffers::const_buffer data;
39+
};
40+
41+
struct read_results
42+
{
43+
span<buffers::const_buffer> messages;
44+
};
45+
46+
/** A websocket client session
47+
*/
48+
template<
49+
class AsyncStream>
50+
class client
51+
{
52+
public:
53+
using stream_type = AsyncStream;
54+
using executor_type = decltype(
55+
std::declval<AsyncStream&>().get_executor());
56+
57+
client(
58+
AsyncStream& stream,
59+
rts::context& ctx);
60+
61+
AsyncStream&
62+
next_layer() noexcept
63+
{
64+
return stream_;
65+
}
66+
67+
/** Perform the websocket handshake
68+
*/
69+
template<
70+
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(
71+
::boost::system::error_code,
72+
::boost::http_proto::response_view)) HandshakeHandler =
73+
asio::default_completion_token_t<executor_type>,
74+
class Decorator = null_decorator
75+
>
76+
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(HandshakeHandler, void(
77+
::boost::system::error_code,
78+
::boost::http_proto::response_view))
79+
async_handshake(
80+
core::string_view host,
81+
core::string_view target,
82+
Decorator decorator = {},
83+
HandshakeHandler&& handler =
84+
asio::default_completion_token_t<executor_type>{}
85+
);
86+
87+
/** Write a complete message
88+
*/
89+
template<class ConstBufferSequence>
90+
auto
91+
async_write(
92+
ConstBufferSequence const& message);
93+
94+
/** Write part of a message
95+
*/
96+
template<class ConstBufferSequence>
97+
auto
98+
async_write_some(
99+
ConstBufferSequence const& data,
100+
bool fin);
101+
102+
/** Write multiple messages
103+
*/
104+
template<class ConstBufferSequence>
105+
auto
106+
async_writev(
107+
ConstBufferSequence const& messages);
108+
109+
private:
110+
template<class Handler>
111+
class handshake_op;
112+
struct run_handshake_op;
113+
114+
AsyncStream& stream_;
115+
rts::context& ctx_;
116+
};
117+
118+
} // ws_io
119+
} // boost
120+
121+
#include <boost/ws_io/impl/client.hpp>
122+
123+
#endif

include/boost/ws_io/impl/client.hpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// Copyright (c) 2025 Vinnie Falco ([email protected])
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/ws_io
8+
//
9+
10+
#ifndef BOOST_WS_IO_IMPL_CLIENT_HPP
11+
#define BOOST_WS_IO_IMPL_CLIENT_HPP
12+
13+
#include <boost/asio/async_result.hpp>
14+
#include <boost/http_proto/response_view.hpp>
15+
#include <boost/asio/coroutine.hpp>
16+
17+
namespace boost {
18+
namespace ws_io {
19+
20+
//------------------------------------------------
21+
22+
template<class AsyncStream>
23+
template<class Handler>
24+
class client<AsyncStream>::
25+
handshake_op
26+
: public asio::coroutine
27+
{
28+
client<AsyncStream>& cs_;
29+
Handler h_;
30+
31+
public:
32+
template<class Handler_>
33+
handshake_op(
34+
client<AsyncStream>& cs,
35+
Handler_&& h,
36+
core::string_view host,
37+
core::string_view target)
38+
: cs_(cs)
39+
, h_(std::forward<Handler_>(h))
40+
{
41+
}
42+
43+
};
44+
45+
//------------------------------------------------
46+
47+
template<class AsyncStream>
48+
struct client<AsyncStream>::
49+
run_handshake_op
50+
{
51+
client<AsyncStream>& self;
52+
53+
using executor_type = typename
54+
client<AsyncStream>::executor_type;
55+
56+
executor_type
57+
get_executor() const noexcept
58+
{
59+
return self.next_layer().get_executor();
60+
}
61+
62+
template<class HandshakeHandler>
63+
void operator()(
64+
HandshakeHandler&& h,
65+
core::string_view host,
66+
core::string_view target
67+
/*,request_type&& req
68+
,detail::sec_ws_key_type key
69+
,response_type* res_p*/
70+
)
71+
{
72+
handshake_op<typename std::decay<
73+
HandshakeHandler>::type>(
74+
self,
75+
std::forward<HandshakeHandler>(h),
76+
host,
77+
target);
78+
}
79+
};
80+
81+
//------------------------------------------------
82+
83+
template<class AsyncStream>
84+
client<AsyncStream>::
85+
client(
86+
AsyncStream& stream,
87+
rts::context& ctx)
88+
: stream_(stream)
89+
, ctx_(ctx)
90+
{
91+
}
92+
93+
template<class AsyncStream>
94+
template<
95+
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(
96+
::boost::system::error_code,
97+
::boost::http_proto::response_view)) HandshakeHandler,
98+
class Decorator>
99+
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(HandshakeHandler, void(
100+
::boost::system::error_code,
101+
::boost::http_proto::response_view))
102+
client<AsyncStream>::
103+
async_handshake(
104+
core::string_view host,
105+
core::string_view target,
106+
Decorator decorator,
107+
HandshakeHandler&& handler)
108+
{
109+
return asio::async_initiate<
110+
HandshakeHandler,
111+
void(system::error_code, http_proto::response_view)>(
112+
run_handshake_op{*this},
113+
handler,
114+
host,
115+
target);
116+
}
117+
118+
} // ws_io
119+
} // boost
120+
121+
#endif

test/unit/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ find_package(OpenSSL REQUIRED)
2323
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES})
2424
source_group("_extra" FILES ${EXTRAFILES})
2525
add_executable(boost_ws_io_tests ${PFILES} ${EXTRAFILES})
26+
if (MSVC)
27+
target_compile_options(boost_ws_io_tests PRIVATE "/bigobj")
28+
endif()
2629
target_include_directories(boost_ws_io_tests PRIVATE . ../../../url/extra/test_suite)
30+
target_include_directories(boost_ws_io_tests PRIVATE "${PROJECT_SOURCE_DIR}")
2731
target_link_libraries(boost_ws_io_tests PRIVATE
2832
OpenSSL::SSL
2933
boost_beast

0 commit comments

Comments
 (0)