diff --git a/daemon/janus.c b/daemon/janus.c index 78310a737..88093f039 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -117,8 +117,7 @@ static const char *janus_send_json_msg(struct websocket_message *wm, JsonBuilder ret = "Tried to send asynchronous event to HTTP"; else { websocket_http_response(wm->wc, code, "application/json", strlen(result)); - if (websocket_write_http(wm->wc, result, done)) - ret = "Failed to write Janus JSON response"; + websocket_write_http(wm->wc, result, done); } } diff --git a/daemon/websocket.c b/daemon/websocket.c index cee93e274..605ba695e 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -126,7 +126,7 @@ size_t websocket_queue_len(struct websocket_conn *wc) { // adds data to output buffer (can be null) and optionally triggers specified response -int websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len, +void websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len, enum lws_write_protocol protocol, bool done) { mutex_lock(&wc->lock); @@ -147,17 +147,17 @@ int websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len, // adds data to output buffer (can be null) and triggers specified response: http or binary websocket -int websocket_write_http_len(struct websocket_conn *wc, const char *msg, size_t len, bool done) { - return websocket_write_raw(wc, msg, len, LWS_WRITE_HTTP, done); +void websocket_write_http_len(struct websocket_conn *wc, const char *msg, size_t len, bool done) { + websocket_write_raw(wc, msg, len, LWS_WRITE_HTTP, done); } -int websocket_write_http(struct websocket_conn *wc, const char *msg, bool done) { - return websocket_write_http_len(wc, msg, msg ? strlen(msg) : 0, done); +void websocket_write_http(struct websocket_conn *wc, const char *msg, bool done) { + websocket_write_http_len(wc, msg, msg ? strlen(msg) : 0, done); } -int websocket_write_text(struct websocket_conn *wc, const char *msg, bool done) { - return websocket_write_raw(wc, msg, strlen(msg), LWS_WRITE_TEXT, done); +void websocket_write_text(struct websocket_conn *wc, const char *msg, bool done) { + websocket_write_raw(wc, msg, strlen(msg), LWS_WRITE_TEXT, done); } -int websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len, bool done) { - return websocket_write_raw(wc, msg, len, LWS_WRITE_BINARY, done); +void websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len, bool done) { + websocket_write_raw(wc, msg, len, LWS_WRITE_BINARY, done); } @@ -314,19 +314,18 @@ void websocket_http_response(struct websocket_conn *wc, int status, const char * wo->content_type = content_type; wo->content_length = content_length; } -const char *websocket_http_complete(struct websocket_conn *wc, int status, const char *content_type, +void websocket_http_complete(struct websocket_conn *wc, int status, const char *content_type, ssize_t content_length, const char *content) { websocket_http_response(wc, status, content_type, content_length); - if (websocket_write_http(wc, content, true)) - return "Failed to write pong response"; - return NULL; + websocket_write_http(wc, content, true); } static const char *websocket_http_ping(struct websocket_message *wm) { ilogs(http, LOG_DEBUG, "Respoding to GET /ping"); - return websocket_http_complete(wm->wc, 200, "text/plain", 5, "pong\n"); + websocket_http_complete(wm->wc, 200, "text/plain", 5, "pong\n"); + return NULL; } @@ -363,7 +362,8 @@ static const char *websocket_http_metrics(struct websocket_message *wm) { g_string_append_printf(outp, " %s\n", m->value_short); } - return websocket_http_complete(wm->wc, 200, "text/plain", outp->len, outp->str); + websocket_http_complete(wm->wc, 200, "text/plain", outp->len, outp->str); + return NULL; } @@ -395,7 +395,8 @@ static const char *websocket_http_cli(struct websocket_message *wm) { size_t len = websocket_queue_len(wm->wc); - return websocket_http_complete(wm->wc, 200, "text/plain", len, NULL); + websocket_http_complete(wm->wc, 200, "text/plain", len, NULL); + return NULL; } diff --git a/include/websocket.h b/include/websocket.h index 7080a2b45..bfc73529e 100644 --- a/include/websocket.h +++ b/include/websocket.h @@ -40,13 +40,13 @@ void websocket_stop(void); // appends to output buffer without triggering a response void websocket_queue_raw(struct websocket_conn *wc, const char *msg, size_t len); // adds data to output buffer (can be null) and optionally triggers specified response -int websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len, +void websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len, enum lws_write_protocol protocol, bool done); // adds data to output buffer (can be null) and triggers specified response: http or binary websocket -int websocket_write_http_len(struct websocket_conn *wc, const char *msg, size_t len, bool done); -int websocket_write_http(struct websocket_conn *wc, const char *msg, bool done); -int websocket_write_text(struct websocket_conn *wc, const char *msg, bool done); -int websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len, bool done); +void websocket_write_http_len(struct websocket_conn *wc, const char *msg, size_t len, bool done); +void websocket_write_http(struct websocket_conn *wc, const char *msg, bool done); +void websocket_write_text(struct websocket_conn *wc, const char *msg, bool done); +void websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len, bool done); // num bytes in output buffer size_t websocket_queue_len(struct websocket_conn *wc);