X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws.c;h=6d488878151169e31f6f552c3d5d096c0c438ca3;hb=a63851bb4726c89d9a3c5755d78d1c4bbc3f3b2e;hp=4e0138a83d4758d39958f7a2cc055fc9cc2d6e56;hpb=c6b4fa9e2c35d5c8bdbf929b6f1622f31afd35c9;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws.c b/src/afb-ws.c index 4e0138a8..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"); @@ -364,9 +364,7 @@ static ssize_t aws_readv(struct afb_ws *ws, const struct iovec *iov, int iovcnt) do { rc = readv(ws->fd, iov, iovcnt); } while(rc == -1 && errno == EINTR); - if (rc == -1 && errno == EAGAIN) { - rc = 0; - } else if (rc == 0) { + if (rc == 0) { errno = EPIPE; rc = -1; } @@ -381,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); } @@ -393,18 +391,28 @@ static void aws_on_readable(struct afb_ws *ws) */ static int aws_read(struct afb_ws *ws, size_t size) { + struct pollfd pfd; 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; - sz = websock_read(ws->ws, &buffer[ws->buffer.size], size); - if ((size_t)sz != size) - return 0; - ws->buffer.size += size; + 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); /* TODO: make fully asynchronous websockets */ + } else { + ws->buffer.size += (size_t)sz; + size -= (size_t)sz; + } + } } return 1; } @@ -490,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) {