8000 first steps to allow sending continuation frame · robokoding/arduinoWebSockets@1a533cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a533cd

Browse files
committed
first steps to allow sending continuation frame
1 parent d5c3e17 commit 1a533cd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/WebSockets.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ void WebSockets::clientDisconnect(WSclient_t * client, uint16_t code, char * rea
6161
* @param payload uint8_t *
6262
* @param length size_t
6363
*/
64-
void WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool mask) {
64+
void WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool mask, bool fin) {
6565

6666
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] ------- send massage frame -------\n", client->num);
67-
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] opCode: %u mask: %u length: %u\n", client->num, opcode, mask, length);
67+
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] fin: %u opCode: %u mask: %u length: %u\n", client->num, fin, opcode, mask, length);
6868

6969
if(opcode == WSop_text) {
7070
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] text: %s\n", client->num, payload);
@@ -80,25 +80,30 @@ void WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
8080
uint8_t i = 0;
8181

8282
//create header
83-
buffer[i] = bit(7); // set Fin
84-
buffer[i++] |= opcode; // set opcode
8583

84+
// byte 0
8685
buffer[i] = 0x00;
86+
if(fin) {
87+
buffer[i] |= bit(7); ///< set Fin
88+
}
89+
buffer[i++] |= opcode; ///< set opcode
8790

91+
// byte 1
92+
buffer[i] = 0x00;
8893
if(mask) {
89-
buffer[i] |= bit(7); // set mask
94+
buffer[i] |= bit(7); ///< set mask
9095
}
9196

9297
if(length < 126) {
9398
buffer[i++] |= length;
9499

95100
} else if(length < 0xFFFF) {
96-
buffer[i++] = 126;
101+
buffer[i++] |= 126;
97102
buffer[i++] = ((length >> 8) & 0xFF);
98103
buffer[i++] = (length & 0xFF);
99104
} else {
100105
// normaly we never get here (to less memory)
101-
buffer[i++] = 127;
106+
buffer[i++] |= 127;
102107
buffer[i++] = 0x00;
103108
buffer[i++] = 0x00;
104109
buffer[i++] = 0x00;

src/WebSockets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class WebSockets {
106106
virtual void messageRecived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length);
107107

108108
void clientDisconnect(WSclient_t * client, uint16_t code, char * reason = NULL, size_t reasonLen = 0);
109-
void sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload = NULL, size_t length = 0, bool mask = false);
109+
void sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload = NULL, size_t length = 0, bool mask = false, bool fin = true);
110110

111111

112112
void handleWebsocket(WSclient_t * client);

0 commit comments

Comments
 (0)
0