+/*
+ * Drops any incoming data and send an error of 'code'
+ */
+static void aws_drop_error(struct afb_ws *ws, uint16_t code)
+{
+ ws->state = waiting;
+ free(aws_pick_buffer(ws).buffer);
+ websock_drop(ws->ws);
+ websock_error(ws->ws, code, NULL, 0);
+}
+
+/*
+ * Reads either text or binary data of 'size' from 'ws' eventually 'last'.
+ */
+static void aws_continue(struct afb_ws *ws, int last, size_t size)
+{
+ struct buf b;
+ int istxt;
+
+ if (!aws_read(ws, size))
+ aws_drop_error(ws, WEBSOCKET_CODE_ABNORMAL);
+ else if (last) {
+ istxt = ws->state == reading_text;
+ ws->state = waiting;
+ b = aws_pick_buffer(ws);
+ b.buffer[b.size] = 0;
+ (istxt ? ws->itf->on_text : ws->itf->on_binary)(ws->closure, b.buffer, b.size);
+ }
+}
+
+/*
+ * Callback when 'text' message received from 'ws' with 'size' and possibly 'last'.
+ */