X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws.c;h=347968185390f04fa5aa4fed844eb849e674dd5a;hb=65bc678960567038ca4d07d1f9c5784b6c7a7834;hp=d0cfc8a8bb0a10fe7f32415511fcd6164c756d35;hpb=5dd6480727cc1ecb12483fc4d971d73176505748;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws.c b/src/afb-ws.c index d0cfc8a8..34796818 100644 --- a/src/afb-ws.c +++ b/src/afb-ws.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 IoT.bzh + * Copyright (C) 2016 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -244,6 +245,40 @@ int afb_ws_text(struct afb_ws *ws, const char *text, size_t length) 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); +} + /* * Sends a binary 'data' of 'length' to the endpoint of 'ws'. * Returns 0 on success or -1 in case of error. @@ -425,4 +460,3 @@ static void aws_on_error(struct afb_ws *ws, uint16_t code, const void *data, siz } -