@@ -61,7 +61,7 @@ void websocket_client::connect()
6161{
6262 state = HTTP_HEADERS;
6363 /* Send headers synchronously */
64- this ->write (
64+ this ->socket_write (
6565 " GET " + this ->path + " HTTP/1.1\r\n "
6666 " Host: " + this ->hostname + " \r\n "
6767 " pragma: no-cache\r\n "
@@ -73,7 +73,7 @@ void websocket_client::connect()
7373 );
7474}
7575
76- bool websocket_client::handle_frame (const std::string& buffer)
76+ bool websocket_client::handle_frame (const std::string& buffer, ws_opcode opcode )
7777{
7878 /* This is a stub for classes that derive the websocket client */
7979 return true ;
@@ -111,17 +111,17 @@ size_t websocket_client::fill_header(unsigned char* outbuf, size_t sendlength, w
111111}
112112
113113
114- void websocket_client::write (const std::string_view data)
114+ void websocket_client::write (const std::string_view data, ws_opcode _opcode )
115115{
116116 if (state == HTTP_HEADERS) {
117117 /* Simple write */
118- ssl_client::write (data);
118+ ssl_client::socket_write (data);
119119 } else {
120120 unsigned char out[MAXHEADERSIZE];
121- size_t s = this ->fill_header (out, data.length (), this ->data_opcode );
121+ size_t s = this ->fill_header (out, data.length (), _opcode == OP_AUTO ? this ->data_opcode : _opcode );
122122 std::string header ((const char *)out, s);
123- ssl_client::write (header);
124- ssl_client::write (data);
123+ ssl_client::socket_write (header);
124+ ssl_client::socket_write (data);
125125 }
126126}
127127
@@ -175,7 +175,7 @@ bool websocket_client::handle_buffer(std::string& buffer)
175175 }
176176 } else if (state == CONNECTED) {
177177 /* Process packets until we can't (buffer will erase data until parseheader returns false) */
178- while (this ->parseheader (buffer)){ }
178+ while (this ->parseheader (buffer)) { }
179179 }
180180
181181 return true ;
@@ -249,7 +249,7 @@ bool websocket_client::parseheader(std::string& data)
249249 handle_ping (data.substr (payloadstartoffset, len));
250250 } else if ((opcode & ~WS_FINBIT) != OP_PONG) { /* Otherwise, handle everything else apart from a PONG. */
251251 /* Pass this frame to the deriving class */
252- this ->handle_frame (data.substr (payloadstartoffset, len));
252+ this ->handle_frame (data.substr (payloadstartoffset, len), static_cast <ws_opcode>(opcode & ~WS_FINBIT) );
253253 }
254254
255255 /* Remove this frame from the input buffer */
@@ -286,8 +286,8 @@ void websocket_client::one_second_timer()
286286 std::string payload = " keepalive" ;
287287 size_t s = this ->fill_header (out, payload.length (), OP_PING);
288288 std::string header ((const char *)out, s);
289- ssl_client::write (header);
290- ssl_client::write (payload);
289+ ssl_client::socket_write (header);
290+ ssl_client::socket_write (payload);
291291 }
292292}
293293
@@ -297,8 +297,8 @@ void websocket_client::handle_ping(const std::string &payload)
297297 unsigned char out[MAXHEADERSIZE];
298298 size_t s = this ->fill_header (out, payload.length (), OP_PONG);
299299 std::string header ((const char *)out, s);
300- ssl_client::write (header);
301- ssl_client::write (payload);
300+ ssl_client::socket_write (header);
301+ ssl_client::socket_write (payload);
302302}
303303
304304void websocket_client::send_close_packet ()
@@ -312,8 +312,8 @@ void websocket_client::send_close_packet()
312312
313313 size_t s = this ->fill_header (out, payload.length (), OP_CLOSE);
314314 std::string header ((const char *)out, s);
315- ssl_client::write (header);
316- ssl_client::write (payload);
315+ ssl_client::socket_write (header);
316+ ssl_client::socket_write (payload);
317317}
318318
319319void websocket_client::error (uint32_t errorcode)
0 commit comments