-
Notifications
You must be signed in to change notification settings - Fork 730
/
sio_client.h
116 lines (74 loc) · 3.11 KB
/
sio_client.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// sio_client.h
//
// Created by Melo Yao on 3/25/15.
//
#ifndef SIO_CLIENT_H
#define SIO_CLIENT_H
#include <string>
#include <functional>
#include "sio_message.h"
#include "sio_socket.h"
namespace asio {
class io_context;
}
namespace sio
{
class client_impl;
struct client_options {
asio::io_context* io_context = nullptr;
};
class client {
public:
enum close_reason
{
close_reason_normal,
close_reason_drop
};
typedef std::function<void(void)> con_listener;
typedef std::function<void(close_reason const& reason)> close_listener;
typedef std::function<void(unsigned, unsigned)> reconnect_listener;
typedef std::function<void(std::string const& nsp)> socket_listener;
client();
client(client_options const& options);
~client();
//set listeners and event bindings.
void set_open_listener(con_listener const& l);
void set_fail_listener(con_listener const& l);
void set_reconnecting_listener(con_listener const& l);
void set_reconnect_listener(reconnect_listener const& l);
void set_close_listener(close_listener const& l);
void set_socket_open_listener(socket_listener const& l);
void set_socket_close_listener(socket_listener const& l);
void clear_con_listeners();
void clear_socket_listeners();
// Client Functions - such as send, etc.
void connect(const std::string& uri);
void connect(const std::string& uri, const message::ptr& auth);
void connect(const std::string& uri, const std::map<std::string,std::string>& query);
void connect(const std::string& uri, const std::map<std::string,std::string>& query, const message::ptr& auth);
void connect(const std::string& uri, const std::map<std::string,std::string>& query,
const std::map<std::string,std::string>& http_extra_headers);
void connect(const std::string& uri, const std::map<std::string,std::string>& query,
const std::map<std::string,std::string>& http_extra_headers, const message::ptr& auth);
void set_reconnect_attempts(int attempts);
void set_reconnect_delay(unsigned millis);
void set_reconnect_delay_max(unsigned millis);
void set_logs_default();
void set_logs_quiet();
void set_logs_verbose();
sio::socket::ptr const& socket(const std::string& nsp = "");
// Closes the connection
void close();
void sync_close();
void set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password);
bool opened() const;
std::string const& get_sessionid() const;
private:
//disable copy constructor and assign operator.
client(client const&){}
void operator=(client const&){}
client_impl* m_impl;
};
}
#endif // __SIO_CLIENT__H__