-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathwebsocket_transport.h
56 lines (41 loc) · 2.41 KB
/
websocket_transport.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma once
#include "transport.h"
#include "logger.h"
#include "signalrclient/websocket_client.h"
#include "connection_impl.h"
namespace signalr
{
class websocket_transport : public transport, public std::enable_shared_from_this<websocket_transport>
{
public:
static std::shared_ptr<transport> create(const std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)>& websocket_client_factory,
const signalr_client_config& signalr_client_config, const logger& logger);
~websocket_transport();
websocket_transport(const websocket_transport&) = delete;
websocket_transport& operator=(const websocket_transport&) = delete;
transport_type get_transport_type() const noexcept override;
void start(const std::string& url, transfer_format transfer_format, std::function<void(std::exception_ptr)> callback) noexcept override;
void stop(std::function<void(std::exception_ptr)> callback) noexcept override;
void on_close(std::function<void(std::exception_ptr)> callback) override;
void send(const std::string& payload, std::function<void(std::exception_ptr)> callback) noexcept override;
void on_receive(std::function<void(std::string&&, std::exception_ptr)>) override;
private:
websocket_transport(const std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)>& websocket_client_factory,
const signalr_client_config& signalr_client_config, const logger& logger);
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> m_websocket_client_factory;
std::shared_ptr<websocket_client> m_websocket_client;
std::mutex m_websocket_client_lock;
std::mutex m_start_stop_lock;
std::function<void(std::string, std::exception_ptr)> m_process_response_callback;
std::function<void(std::exception_ptr)> m_close_callback;
signalr_client_config m_signalr_client_config;
bool m_disconnected;
std::shared_ptr<cancellation_token_source> m_receive_loop_task;
transfer_format m_transfer_format;
void receive_loop();
std::shared_ptr<websocket_client> safe_get_websocket_client();
};
}