aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-ws.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-12 22:50:35 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-12 22:50:35 +0200
commit7b97a7f27578d7f4ce7cc994e5df303ac5d9c886 (patch)
tree327277b7af9e21b28fcbc2292f17a6338b33d28f /src/afb-ws.c
parent3e775a79aa6ea82f93b2fc03f58ad261a17c73ca (diff)
websocket client library
This introduce 2 files for creating client of websockets x-afb-json1: - afb-wsj1.c - afb-ws-client.c The file afb-wsj1.c implements the protocol x-afb-json1 on top of afb-ws.c. It could be used to rewrite afb-ws-json1. The file afb-ws-client.c implements a light version of the websocket handshaking to open a afb-wsj1 based on an uri. Change-Id: Ie53a3b4ff91a9efac32b667b57f8005266db6001 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-ws.c')
-rw-r--r--src/afb-ws.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/afb-ws.c b/src/afb-ws.c
index d0cfc8a8..5e8732db 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <sys/uio.h>
#include <string.h>
+#include <stdarg.h>
#include <systemd/sd-event.h>
@@ -245,6 +246,39 @@ int afb_ws_text(struct afb_ws *ws, const char *text, size_t 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);
+ s = va_arg(args, const char *);
+ }
+ va_end(args);
+ return websock_text_v(ws->ws, 1, ios, count);
+}
+
+/*
* Sends a binary 'data' of 'length' to the endpoint of 'ws'.
* Returns 0 on success or -1 in case of error.
*/
@@ -425,4 +459,3 @@ static void aws_on_error(struct afb_ws *ws, uint16_t code, const void *data, siz
}
-