From e1d2626f107224f049e94471e422cef885a6e3e0 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Wed, 8 Apr 2015 20:00:09 +0200 Subject: WS: send messages in blocks --- json-rpc-shell.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/json-rpc-shell.c b/json-rpc-shell.c index 473560c..a344f2b 100644 --- a/json-rpc-shell.c +++ b/json-rpc-shell.c @@ -1066,16 +1066,19 @@ backend_ws_send_message (struct app_context *ctx, return false; str_pack_u32 (&header, mask); - // XXX: maybe we should do this in a loop, who knows how large this can be - char masked[len]; - memcpy (masked, data, len); - ws_parser_unmask (masked, len, mask); - - bool result = true; - if (!backend_ws_write (ctx, header.str, header.len) - || !backend_ws_write (ctx, masked, len)) - result = false; + bool result = backend_ws_write (ctx, header.str, header.len); str_free (&header); + while (result && len) + { + size_t block_size = MIN (len, 1 << 16); + char masked[block_size]; + memcpy (masked, data, block_size); + ws_parser_unmask (masked, block_size, mask); + result = backend_ws_write (ctx, masked, block_size); + + len -= block_size; + data = (const uint8_t *) data + block_size; + } return result; } -- cgit v1.2.3-70-g09d2