From 2243a0dd1adc75530bed663db808971789729df3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 10 Apr 2017 12:00:14 +0200 Subject: [PATCH] Websocket client select if looping or not MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allows the client to tell websocket module to not loop on messages. Change-Id: Iaa1025ce5442a5659554ba66fcc5869a1e8659b4 Signed-off-by: José Bollo --- src/afb-ws.c | 2 +- src/websock.c | 12 +++++++++++- src/websock.h | 2 +- 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); -- 2.16.6