23
23
#include < dpp/export.h>
24
24
#include < string>
25
25
#include < map>
26
- #include < vector>
27
- #include < variant>
28
26
#include < dpp/sslclient.h>
29
27
30
28
namespace dpp {
@@ -37,7 +35,7 @@ enum websocket_protocol_t : uint8_t {
37
35
* @brief JSON data, text, UTF-8 character set
38
36
*/
39
37
ws_json = 0 ,
40
-
38
+
41
39
/* *
42
40
* @brief Erlang Term Format (ETF) binary protocol
43
41
*/
@@ -68,32 +66,32 @@ enum ws_opcode : uint8_t {
68
66
/* *
69
67
* @brief Continuation.
70
68
*/
71
- OP_CONTINUATION = 0x00 ,
69
+ OP_CONTINUATION = 0x00 ,
72
70
73
71
/* *
74
72
* @brief Text frame.
75
73
*/
76
- OP_TEXT = 0x01 ,
74
+ OP_TEXT = 0x01 ,
77
75
78
76
/* *
79
77
* @brief Binary frame.
80
78
*/
81
- OP_BINARY = 0x02 ,
79
+ OP_BINARY = 0x02 ,
82
80
83
81
/* *
84
82
* @brief Close notification with close code.
85
83
*/
86
- OP_CLOSE = 0x08 ,
84
+ OP_CLOSE = 0x08 ,
87
85
88
86
/* *
89
87
* @brief Low level ping.
90
88
*/
91
- OP_PING = 0x09 ,
89
+ OP_PING = 0x09 ,
92
90
93
91
/* *
94
92
* @brief Low level pong.
95
93
*/
96
- OP_PONG = 0x0a
94
+ OP_PONG = 0x0a
97
95
};
98
96
99
97
/* *
@@ -130,7 +128,7 @@ class DPP_EXPORT websocket_client : public ssl_client {
130
128
* @param buffer The buffer to operate on. Will modify the string removing completed items from the head of the queue
131
129
* @return true if a complete header has been received
132
130
*/
133
- bool parseheader (std::string & buffer);
131
+ bool parseheader (std::string& buffer);
134
132
135
133
/* *
136
134
* @brief Unpack a frame and pass completed frames up the stack.
@@ -139,7 +137,7 @@ class DPP_EXPORT websocket_client : public ssl_client {
139
137
* @param first True if is the first element (reserved for future use)
140
138
* @return true if a complete frame has been received
141
139
*/
142
- bool unpack (std::string & buffer, uint32_t offset, bool first = true );
140
+ bool unpack (std::string& buffer, uint32_t offset, bool first = true );
143
141
144
142
/* *
145
143
* @brief Fill a header for outbound messages
@@ -151,11 +149,10 @@ class DPP_EXPORT websocket_client : public ssl_client {
151
149
size_t fill_header (unsigned char * outbuf, size_t sendlength, ws_opcode opcode);
152
150
153
151
/* *
154
- * @brief Handle ping and pong requests.
155
- * @param ping True if this is a ping, false if it is a pong
156
- * @param payload The ping payload, to be returned as-is for a ping
152
+ * @brief Handle ping requests.
153
+ * @param payload The ping payload, to be returned as-is for a pong
157
154
*/
158
- void handle_ping_pong ( bool ping, const std::string & payload);
155
+ void handle_ping ( const std::string& payload);
159
156
160
157
protected:
161
158
@@ -168,7 +165,7 @@ class DPP_EXPORT websocket_client : public ssl_client {
168
165
* @brief Get websocket state
169
166
* @return websocket state
170
167
*/
171
- ws_state get_state ();
168
+ [[nodiscard]] ws_state get_state () const ;
172
169
173
170
public:
174
171
@@ -181,41 +178,41 @@ class DPP_EXPORT websocket_client : public ssl_client {
181
178
* @note Voice websockets only support OP_TEXT, and other websockets must be
182
179
* OP_BINARY if you are going to send ETF.
183
180
*/
184
- websocket_client (const std::string & hostname, const std::string & port = " 443" , const std::string & urlpath = " " , ws_opcode opcode = OP_BINARY);
181
+ websocket_client (const std::string& hostname, const std::string& port = " 443" , const std::string& urlpath = " " , ws_opcode opcode = OP_BINARY);
185
182
186
183
/* *
187
184
* @brief Destroy the websocket client object
188
185
*/
189
- virtual ~websocket_client () = default ;
186
+ virtual ~websocket_client () = default ;
190
187
191
188
/* *
192
189
* @brief Write to websocket. Encapsulates data in frames if the status is CONNECTED.
193
190
* @param data The data to send.
194
191
*/
195
- virtual void write (const std::string & data);
192
+ virtual void write (const std::string_view data);
196
193
197
194
/* *
198
195
* @brief Processes incoming frames from the SSL socket input buffer.
199
196
* @param buffer The buffer contents. Can modify this value removing the head elements when processed.
200
197
*/
201
- virtual bool handle_buffer (std::string & buffer);
198
+ virtual bool handle_buffer (std::string& buffer);
202
199
203
200
/* *
204
201
* @brief Close websocket
205
202
*/
206
- virtual void close ();
203
+ virtual void close ();
207
204
208
205
/* *
209
206
* @brief Receives raw frame content only without headers
210
- *
207
+ *
211
208
* @param buffer The buffer contents
212
209
* @return True if the frame was successfully handled. False if no valid frame is in the buffer.
213
210
*/
214
- virtual bool handle_frame (const std::string & buffer);
211
+ virtual bool handle_frame (const std::string& buffer);
215
212
216
213
/* *
217
214
* @brief Called upon error frame.
218
- *
215
+ *
219
216
* @param errorcode The error code from the websocket server
220
217
*/
221
218
virtual void error (uint32_t errorcode);
0 commit comments