summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-10 12:00:14 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-10 12:00:14 +0200
commit2243a0dd1adc75530bed663db808971789729df3 (patch)
treed1e003ab8b2db0c3dd9f4a685155d51be2e9681e
parent5d248158cc380d0a164fa56b46a7bdede4115407 (diff)
Websocket client select if looping or not
Allows the client to tell websocket module to not loop on messages. Change-Id: Iaa1025ce5442a5659554ba66fcc5869a1e8659b4 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-ws.c2
-rw-r--r--src/websock.c12
-rw-r--r--src/websock.h2
3 files changed, 13 insertions, 3 deletions
diff --git a/src/afb-ws.c b/src/afb-ws.c
index 5af2434f..cc852b20 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -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);
}
diff --git a/src/websock.c b/src/websock.c
index 04661c11..f79feb5e 100644
--- a/src/websock.c
+++ b/src/websock.c
@@ -303,7 +303,7 @@ static int check_control_header(struct websock *ws)
return 1;
}
-int websock_dispatch(struct websock *ws)
+int websock_dispatch(struct websock *ws, int loop)
{
uint16_t code;
loop:
@@ -418,16 +418,22 @@ loop:
ws->itf->on_continue(ws->closure,
FRAME_GET_FIN(ws->header[0]),
(size_t) ws->length);
+ if (!loop)
+ return 0;
break;
case OPCODE_TEXT:
ws->itf->on_text(ws->closure,
FRAME_GET_FIN(ws->header[0]),
(size_t) ws->length);
+ if (!loop)
+ return 0;
break;
case OPCODE_BINARY:
ws->itf->on_binary(ws->closure,
FRAME_GET_FIN(ws->header[0]),
(size_t) ws->length);
+ if (!loop)
+ return 0;
break;
case OPCODE_CLOSE:
if (ws->length == 0)
@@ -447,6 +453,8 @@ loop:
websock_pong(ws, NULL, 0);
}
ws->state = STATE_INIT;
+ if (!loop)
+ return 0;
break;
case OPCODE_PONG:
if (ws->itf->on_pong)
@@ -454,6 +462,8 @@ loop:
else
websock_drop(ws);
ws->state = STATE_INIT;
+ if (!loop)
+ return 0;
break;
default:
goto protocol_error;
diff --git a/src/websock.h b/src/websock.h
index 0e6807ea..da44a88b 100644
--- a/src/websock.h
+++ b/src/websock.h
@@ -70,7 +70,7 @@ extern int websock_continue_v(struct websock *ws, int last, const struct iovec *
extern ssize_t websock_read(struct websock *ws, void *buffer, size_t size);
extern int websock_drop(struct websock *ws);
-extern int websock_dispatch(struct websock *ws);
+extern int websock_dispatch(struct websock *ws, int loop);
extern struct websock *websock_create_v13(const struct websock_itf *itf, void *closure);
extern void websock_destroy(struct websock *ws);