algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
Loading...
Searching...
No Matches
ws_session.hpp
1
#pragma once
2
3
#include "./ws_session_base.hpp"
4
5
namespace
algotradelib::network
{
6
12
class
WsSession
:
public
WebSocketSessionBase<WsSession, websocket::stream<beast::tcp_stream>> {
13
public
:
22
WsSession
(
23
net::io_context& ioc,
24
std::string host,
25
std::string port,
26
std::string target =
"/"
,
27
std::map<std::string, std::string> headers = {}
28
)
29
:
WebSocketSessionBase
(
30
ioc,
31
std::move(host),
32
std::move(port),
33
WebSocketSessionOptions
{std::move(target), std::move(headers)}
34
) {}
35
36
private
:
37
template
<
typename
,
typename
>
38
friend
class
WebSocketSessionBase;
39
friend
struct
WebSocketSessionTestAccess;
40
using
Stream = websocket::stream<beast::tcp_stream>;
41
42
void
do_connect() {
43
if
(
connected_
||
connecting_
||
closing_
||
stop_requested_
) {
44
return
;
45
}
46
ws_
= std::make_unique<Stream>(
strand_
);
47
buffer_
.consume(
buffer_
.size());
48
start_resolve
();
49
}
50
51
void
on_connect(beast::error_code error, tcp::resolver::results_type::endpoint_type endpoint) {
52
if
(error) {
53
fail
(
"connect"
, error);
54
return
;
55
}
56
if
(
abandon_if_closing
()) {
57
return
;
58
}
59
host_header_
=
host_
+
":"
+ std::to_string(endpoint.port());
60
start_ws_handshake
();
61
}
62
};
63
64
}
// namespace algotradelib::network
algotradelib::network::WebSocketSessionBase
The base of the WebSocket clients WsSession and WssSession: connecting, sending, receiving,...
Definition
ws_session_base.hpp:72
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::host_
std::string host_
Definition
ws_session_base.hpp:187
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::abandon_if_closing
bool abandon_if_closing()
Definition
ws_session_base.hpp:255
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::start_ws_handshake
void start_ws_handshake()
Definition
ws_session_base.hpp:229
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::fail
void fail(std::string_view stage, beast::error_code error)
Definition
ws_session_base.hpp:275
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::stop_requested_
bool stop_requested_
Definition
ws_session_base.hpp:203
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::host_header_
std::string host_header_
Definition
ws_session_base.hpp:191
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::connected_
bool connected_
Definition
ws_session_base.hpp:195
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::start_resolve
void start_resolve()
Definition
ws_session_base.hpp:218
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::connecting_
bool connecting_
Definition
ws_session_base.hpp:197
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::buffer_
beast::flat_buffer buffer_
Definition
ws_session_base.hpp:183
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::closing_
bool closing_
Definition
ws_session_base.hpp:199
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::ws_
std::unique_ptr< websocket::stream< beast::tcp_stream > > ws_
Definition
ws_session_base.hpp:181
algotradelib::network::WebSocketSessionBase< WsSession, websocket::stream< beast::tcp_stream > >::strand_
net::strand< net::io_context::executor_type > strand_
Definition
ws_session_base.hpp:175
algotradelib::network::WsSession::WsSession
WsSession(net::io_context &ioc, std::string host, std::string port, std::string target="/", std::map< std::string, std::string > headers={})
Constructs a session.
Definition
ws_session.hpp:22
algotradelib::network
HTTP and WebSocket transport, OAuth tokens, and request pacing.
Definition
http_client.hpp:45
algotradelib::network::WebSocketSessionOptions
Options for a WebSocket session (WsSession, WssSession).
Definition
ws_session_base.hpp:40
algotradelib
src
network
ws_session.hpp
Generated by
1.18.0