aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-09-15 15:19:23 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-09-15 15:19:23 +0200
commita6401ca78446610ffadb7b63c90937caa47d065a (patch)
treebfb101ce83988a6cdb096926fcc0e5ec13afe1aa
parentc6b4fa9e2c35d5c8bdbf929b6f1622f31afd35c9 (diff)
afb-ws: fix of handling EAGAIN for websockets
Change-Id: I5a48bff9b1ce50adb48884ad15a9cfc7bd7a066d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-ws.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/afb-ws.c b/src/afb-ws.c
index 4e0138a8..d159c28a 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -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;
}
@@ -393,6 +391,7 @@ 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;
@@ -401,10 +400,19 @@ static int aws_read(struct afb_ws *ws, size_t size)
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;
+ do {
+ 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);
+ } else {
+ ws->buffer.size += (size_t)sz;
+ size -= (size_t)sz;
+ }
+ } while (size != 0);
}
return 1;
}