Browse Source

MT#55283 eliminate useless return values

These functions now cannot fail and so returning a value is pointless.

Change-Id: I062449f30f05fb3efa4ba520004a13de3a0abd5a
pull/1640/head
Richard Fuchs 3 years ago
parent
commit
26cc168f83
3 changed files with 25 additions and 24 deletions
  1. +1
    -2
      daemon/janus.c
  2. +19
    -17
      daemon/websocket.c
  3. +5
    -5
      include/websocket.h

+ 1
- 2
daemon/janus.c View File

@ -111,8 +111,7 @@ static const char *janus_send_json_msg(struct websocket_message *wm, JsonBuilder
ret = "Tried to send asynchronous event to HTTP"; ret = "Tried to send asynchronous event to HTTP";
else { else {
websocket_http_response(wm->wc, code, "application/json", strlen(result)); 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);
} }
} }


+ 19
- 17
daemon/websocket.c View File

@ -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 // 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) enum lws_write_protocol protocol, bool done)
{ {
mutex_lock(&wc->lock); 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 // 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);
} }
@ -332,19 +332,18 @@ void websocket_http_response(struct websocket_conn *wc, int status, const char *
wo->content_type = content_type; wo->content_type = content_type;
wo->content_length = content_length; 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) ssize_t content_length, const char *content)
{ {
websocket_http_response(wc, status, content_type, content_length); 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) { static const char *websocket_http_ping(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Respoding to GET /ping"); 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;
} }
@ -381,7 +380,8 @@ static const char *websocket_http_metrics(struct websocket_message *wm) {
g_string_append_printf(outp, " %s\n", m->value_short); 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;
} }
@ -413,7 +413,8 @@ static const char *websocket_http_cli(struct websocket_message *wm) {
size_t len = websocket_queue_len(wm->wc); 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;
} }
@ -563,7 +564,8 @@ static int websocket_http_post(struct websocket_conn *wc) {
static const char *websocket_http_options_generic(struct websocket_message *wm) { static const char *websocket_http_options_generic(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Respoding to OPTIONS"); ilogs(http, LOG_DEBUG, "Respoding to OPTIONS");
return websocket_http_complete(wm->wc, 200, NULL, 0, NULL);
websocket_http_complete(wm->wc, 200, NULL, 0, NULL);
return NULL;
} }


+ 5
- 5
include/websocket.h View File

@ -41,13 +41,13 @@ void websocket_stop(void);
// appends to output buffer without triggering a response // appends to output buffer without triggering a response
void websocket_queue_raw(struct websocket_conn *wc, const char *msg, size_t len); 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 // 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); enum lws_write_protocol protocol, bool done);
// adds data to output buffer (can be null) and triggers specified response: http or binary websocket // 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 // num bytes in output buffer
size_t websocket_queue_len(struct websocket_conn *wc); size_t websocket_queue_len(struct websocket_conn *wc);


Loading…
Cancel
Save