aboutsummaryrefslogtreecommitdiff
path: root/json-rpc-shell.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-08 20:00:09 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-08 20:00:47 +0200
commite1d2626f107224f049e94471e422cef885a6e3e0 (patch)
tree4668634265441f88434db38b4b54a9828ea44537 /json-rpc-shell.c
parent808393c537f09804c9834b022c91c5d39c3bd7f7 (diff)
downloadjson-rpc-shell-e1d2626f107224f049e94471e422cef885a6e3e0.tar.gz
json-rpc-shell-e1d2626f107224f049e94471e422cef885a6e3e0.tar.xz
json-rpc-shell-e1d2626f107224f049e94471e422cef885a6e3e0.zip
WS: send messages in blocks
Diffstat (limited to 'json-rpc-shell.c')
-rw-r--r--json-rpc-shell.c21
1 files 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;
}