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)
return 0;
pfd.fd = ws->fd;
pfd.events = POLLIN;
- poll(&pfd, 1, 10);
+ poll(&pfd, 1, 10); /* TODO: make fully asynchronous websockets */
} else {
ws->buffer.size += (size_t)sz;
size -= (size_t)sz;
}
- } while (size != 0);
+ }
}
return 1;
}
}
/*
- * Callback when 'close' command received from 'ws' with 'code' and 'size'.
+ * Callback when 'continue' command received from 'ws' with 'code' and 'size'.
*/
static void aws_on_continue(struct afb_ws *ws, int last, size_t size)
{