X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws.c;h=6d488878151169e31f6f552c3d5d096c0c438ca3;hb=2c0d6171441fc3612c3cf60fda70a1d90b18be64;hp=d159c28ab66df719eaac7ab21124a92a69dbe0cb;hpb=a6401ca78446610ffadb7b63c90937caa47d065a;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws.c b/src/afb-ws.c index d159c28a..6d488878 100644 --- a/src/afb-ws.c +++ b/src/afb-ws.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -379,7 +379,7 @@ static void aws_on_readable(struct afb_ws *ws) int rc; assert(ws->ws != NULL); - rc = websock_dispatch(ws->ws); + rc = websock_dispatch(ws->ws, 0); if (rc < 0 && errno == EPIPE) afb_ws_hangup(ws); } @@ -395,24 +395,24 @@ 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) 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; } @@ -498,7 +498,7 @@ static void aws_on_binary(struct afb_ws *ws, int last, size_t size) } /* - * 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) {