summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-01 22:14:34 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-01 22:14:34 +0200
commitf7b298ae1c4f46bba07ddf9f9813c8fa85187d12 (patch)
tree205124024253b34cbf220f802abef3b2cd862d89
parent9b2c70bf87bb3272cb325f3a9ecf69cd0bd53ba8 (diff)
Fix bug in websocket on empty packets
Change-Id: I21d6e36df183b798539cf2a378976cc595a77029 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-ws.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/afb-ws.c b/src/afb-ws.c
index b157a49f..6d488878 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -395,12 +395,12 @@ static int aws_read(struct afb_ws *ws, size_t size)
ssize_t sz;
char *buffer;
- if (size != 0) {
+ if (size != 0 || ws->buffer.buffer == NULL) {
buffer = realloc(ws->buffer.buffer, ws->buffer.size + size + 1);
if (buffer == NULL)
return 0;
ws->buffer.buffer = buffer;
- do {
+ while (size != 0) {
sz = websock_read(ws->ws, &buffer[ws->buffer.size], size);
if (sz < 0) {
if (errno != EAGAIN)
@@ -412,7 +412,7 @@ static int aws_read(struct afb_ws *ws, size_t size)
ws->buffer.size += (size_t)sz;
size -= (size_t)sz;
}
- } while (size != 0);
+ }
}
return 1;
}