+ aws_disconnect(ws, 1);
+}
+
+/*
+ * 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);