Skip to content

Commit f4ef3e3

Browse files
committed
[WIP] adding stuff
1 parent 9187d7b commit f4ef3e3

File tree

10 files changed

+872
-7
lines changed

10 files changed

+872
-7
lines changed

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/http_proto/context.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+
http_proto::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+
http_proto::context& ctx_;
116+
};
117+
118+
} // ws_io
119+
} // boost
120+
121+
#include <boost/ws_io/impl/client.hpp>
122+
123+
#endif
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+
http_proto::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: 5 additions & 1 deletion
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-
target_include_directories(boost_ws_io_tests PRIVATE . ../../../url/extra/test_suite)
26+
if (MSVC)
27+
target_compile_options(boost_ws_io_tests PRIVATE "/bigobj")
28+
endif()
29+
target_include_directories(boost_ws_io_tests PRIVATE . ../../../url/extra)
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

test/unit/client.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/ws_io
8+
//
9+
10+
#include <boost/ws_io/client.hpp>
11+
#include <boost/http_proto/context.hpp>
12+
#include <boost/http_proto/parser.hpp>
13+
#include "test/unit/server.hpp"
14+
#include "test_suite.hpp"
15+
16+
namespace boost {
17+
namespace ws_io {
18+
19+
struct client_test
20+
{
21+
void
22+
run()
23+
{
24+
http_proto::context ctx;
25+
http_proto::parser::config_base cfg;
26+
http_proto::install_parser_service(ctx, cfg);
27+
28+
test::server srv;
29+
auto sock = srv.connect();
30+
client<test::socket_type> cs(sock, ctx);
31+
cs.async_handshake(
32+
"localhost",
33+
"/",
34+
[](http_proto::request&)
35+
{
36+
},
37+
test::success_handler());
38+
//srv.run();
39+
}
40+
};
41+
42+
TEST_SUITE(
43+
client_test,
44+
"boost.ws_io.client");
45+
46+
} // ws_io
47+
} // boost

test/unit/error.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// Test that header file is self-contained.
1111
#include <boost/ws_io/error.hpp>
1212

13-
#include <boost/beast/version.hpp>
14-
1513
#include "test_suite.hpp"
1614

1715
namespace boost {

0 commit comments

Comments
 (0)