Skip to content

Commit f8fb447

Browse files
committed
extmod/modwebsocket: write(): Support write size beyond 125 bytes.
1 parent 7063210 commit f8fb447

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

extmod/modwebsocket.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,18 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
180180

181181
STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
182182
mp_obj_websocket_t *self = self_in;
183-
assert(size < 126);
184-
byte header[] = {0x80 | (self->opts & FRAME_OPCODE_MASK), size};
183+
assert(size < 0x10000);
184+
byte header[4] = {0x80 | (self->opts & FRAME_OPCODE_MASK)};
185+
int hdr_sz;
186+
if (size < 126) {
187+
header[1] = size;
188+
hdr_sz = 2;
189+
} else {
190+
header[1] = 126;
191+
header[2] = size >> 8;
192+
header[3] = size & 0xff;
193+
hdr_sz = 4;
194+
}
185195

186196
mp_obj_t dest[3];
187197
if (self->opts & BLOCKING_WRITE) {
@@ -190,7 +200,7 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si
190200
mp_call_method_n_kw(1, 0, dest);
191201
}
192202

193-
mp_uint_t out_sz = mp_stream_writeall(self->sock, header, sizeof(header), errcode);
203+
mp_uint_t out_sz = mp_stream_writeall(self->sock, header, hdr_sz, errcode);
194204
if (out_sz != MP_STREAM_ERROR) {
195205
out_sz = mp_stream_writeall(self->sock, buf, size, errcode);
196206
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy