+ aws_disconnect(ws, 0);
+ free(ws);
+}
+
+/*
+ * Hangup the websocket 'ws'
+ */
+void afb_ws_hangup(struct afb_ws *ws)
+{
+ aws_disconnect(ws, 1);
+}
+
+/*
+ * Is the websocket 'ws' still connected ?
+ */
+int afb_ws_is_connected(struct afb_ws *ws)
+{
+ return ws->ws != NULL;
+}
+
+/*
+ * Sends a 'close' command to the endpoint of 'ws' with the 'code' and the
+ * 'reason' (that can be NULL and that else should not be greater than 123
+ * characters).
+ * Returns 0 on success or -1 in case of error.
+ */
+int afb_ws_close(struct afb_ws *ws, uint16_t code, const char *reason)
+{
+ if (ws->ws == NULL) {
+ /* disconnected */
+ errno = EPIPE;
+ return -1;
+ }
+ return websock_close(ws->ws, code, reason, reason == NULL ? 0 : strlen(reason));
+}
+
+/*
+ * Sends a 'close' command to the endpoint of 'ws' with the 'code' and the
+ * 'reason' (that can be NULL and that else should not be greater than 123
+ * characters).
+ * Raise an error after 'close' command is sent.
+ * Returns 0 on success or -1 in case of error.
+ */
+int afb_ws_error(struct afb_ws *ws, uint16_t code, const char *reason)
+{
+ if (ws->ws == NULL) {
+ /* disconnected */
+ errno = EPIPE;
+ return -1;
+ }
+ return websock_error(ws->ws, code, reason, reason == NULL ? 0 : strlen(reason));
+}
+
+/*
+ * Sends a 'text' of 'length' to the endpoint of 'ws'.
+ * Returns 0 on success or -1 in case of error.
+ */
+int afb_ws_text(struct afb_ws *ws, const char *text, size_t length)
+{
+ if (ws->ws == NULL) {
+ /* disconnected */
+ errno = EPIPE;
+ return -1;
+ }
+ return websock_text(ws->ws, 1, text, length);
+}
+
+/*
+ * Sends a variable list of texts to the endpoint of 'ws'.
+ * Returns 0 on success or -1 in case of error.
+ */
+int afb_ws_texts(struct afb_ws *ws, ...)
+{
+ va_list args;
+ struct iovec ios[32];
+ int count;
+ const char *s;
+
+ if (ws->ws == NULL) {
+ /* disconnected */
+ errno = EPIPE;
+ return -1;
+ }
+
+ count = 0;
+ va_start(args, ws);
+ s = va_arg(args, const char *);
+ while (s != NULL) {
+ if (count == 32) {
+ errno = EINVAL;
+ return -1;
+ }
+ ios[count].iov_base = (void*)s;
+ ios[count].iov_len = strlen(s);
+ count++;
+ s = va_arg(args, const char *);
+ }
+ va_end(args);
+ return websock_text_v(ws->ws, 1, ios, count);