Browse Source

TT#89352 switch `done` flag to bool type

Change-Id: I6206a13779ccd44a575654f6af8627492d4b13ed
pull/1346/head
Richard Fuchs 4 years ago
parent
commit
b945104b5e
2 changed files with 16 additions and 15 deletions
  1. +10
    -10
      daemon/websocket.c
  2. +6
    -5
      include/websocket.h

+ 10
- 10
daemon/websocket.c View File

@ -122,7 +122,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, int websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len,
enum lws_write_protocol protocol, int done)
enum lws_write_protocol protocol, bool done)
{ {
mutex_lock(&wc->lock); mutex_lock(&wc->lock);
__websocket_queue_raw(wc, msg, len); __websocket_queue_raw(wc, msg, len);
@ -142,16 +142,16 @@ 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, int done) {
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); return websocket_write_raw(wc, msg, len, LWS_WRITE_HTTP, done);
} }
int websocket_write_http(struct websocket_conn *wc, const char *msg, int 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); return websocket_write_http_len(wc, msg, msg ? strlen(msg) : 0, done);
} }
int websocket_write_text(struct websocket_conn *wc, const char *msg, int 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); return 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, int 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); return websocket_write_raw(wc, msg, len, LWS_WRITE_BINARY, done);
} }
@ -166,7 +166,7 @@ void websocket_write_next(struct websocket_conn *wc) {
static const char *websocket_echo_process(struct websocket_message *wm) { static const char *websocket_echo_process(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Returning %lu bytes websocket echo from %s", (unsigned long) wm->body->len, ilogs(http, LOG_DEBUG, "Returning %lu bytes websocket echo from %s", (unsigned long) wm->body->len,
endpoint_print_buf(&wm->wc->endpoint)); endpoint_print_buf(&wm->wc->endpoint));
websocket_write_binary(wm->wc, wm->body->str, wm->body->len, 1);
websocket_write_binary(wm->wc, wm->body->str, wm->body->len, true);
return NULL; return NULL;
} }
@ -302,7 +302,7 @@ const char *websocket_http_complete(struct websocket_conn *wc, int status, const
{ {
if (websocket_http_response(wc, status, content_type, content_length)) if (websocket_http_response(wc, status, content_type, content_length))
return "Failed to write response HTTP headers"; return "Failed to write response HTTP headers";
if (websocket_write_http(wc, content, 1))
if (websocket_write_http(wc, content, true))
return "Failed to write pong response"; return "Failed to write pong response";
return NULL; return NULL;
} }
@ -395,7 +395,7 @@ static const char *websocket_cli_process(struct websocket_message *wm) {
}; };
cli_handle(&uri_cmd, &cw); cli_handle(&uri_cmd, &cw);
websocket_write_binary(wm->wc, NULL, 0, 1);
websocket_write_binary(wm->wc, NULL, 0, true);
return NULL; return NULL;
} }
@ -405,7 +405,7 @@ static void websocket_ng_send_ws(str *cookie, str *body, const endpoint_t *sin,
websocket_queue_raw(wc, cookie->s, cookie->len); websocket_queue_raw(wc, cookie->s, cookie->len);
websocket_queue_raw(wc, " ", 1); websocket_queue_raw(wc, " ", 1);
websocket_queue_raw(wc, body->s, body->len); websocket_queue_raw(wc, body->s, body->len);
websocket_write_binary(wc, NULL, 0, 1);
websocket_write_binary(wc, NULL, 0, true);
} }
static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin, void *p1) { static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin, void *p1) {
struct websocket_conn *wc = p1; struct websocket_conn *wc = p1;
@ -414,7 +414,7 @@ static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin
websocket_queue_raw(wc, cookie->s, cookie->len); websocket_queue_raw(wc, cookie->s, cookie->len);
websocket_queue_raw(wc, " ", 1); websocket_queue_raw(wc, " ", 1);
websocket_queue_raw(wc, body->s, body->len); websocket_queue_raw(wc, body->s, body->len);
websocket_write_http(wc, NULL, 1);
websocket_write_http(wc, NULL, true);
} }
static void __ng_buf_free(void *p) { static void __ng_buf_free(void *p) {


+ 6
- 5
include/websocket.h View File

@ -1,6 +1,7 @@
#ifndef __WEBSOCKET_H__ #ifndef __WEBSOCKET_H__
#define __WEBSOCKET_H__ #define __WEBSOCKET_H__
#include <stdbool.h>
#include "str.h" #include "str.h"
@ -38,12 +39,12 @@ void websocket_start(void);
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, int websocket_write_raw(struct websocket_conn *wc, const char *msg, size_t len,
enum lws_write_protocol protocol, int 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, int done);
int websocket_write_http(struct websocket_conn *wc, const char *msg, int done);
int websocket_write_text(struct websocket_conn *wc, const char *msg, int done);
int websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len, int done);
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);
// 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