Websocket client select if looping or not
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 10 Apr 2017 10:00:14 +0000 (12:00 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 10 Apr 2017 10:00:14 +0000 (12:00 +0200)
Allows the client to tell websocket module to not
loop on messages.

Change-Id: Iaa1025ce5442a5659554ba66fcc5869a1e8659b4
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-ws.c
src/websock.c
src/websock.h

index 5af2434..cc852b2 100644 (file)
@@ -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);
 }
index 04661c1..f79feb5 100644 (file)
@@ -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;
index 0e6807e..da44a88 100644 (file)
@@ -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);