From a0876e532c1df9cd0d363e1e5c191096f9d7eeb0 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 10 Aug 2020 22:36:00 +0200 Subject: [PATCH] [websocket] Prefix globals with websocket_ Avoids e.g. "event" being both the name of a global and a parameter name in send_notify_reply() credit lgtm.com --- src/websocket.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/websocket.c b/src/websocket.c index 3b8ce39f..29c17de8 100644 --- a/src/websocket.c +++ b/src/websocket.c @@ -40,14 +40,14 @@ static struct lws_context *context; static pthread_t tid_websocket; static int websocket_port; -static bool ws_exit = false; +static bool websocket_exit = false; // Event mask of events to notify websocket clients -static short events; +static short websocket_events; // Event mask of events processed by the writeable callback -static short write_events; +static short websocket_write_events; // Counter for events to keep track of when to write -static unsigned short write_events_counter; +static unsigned short websocket_write_events_counter; @@ -56,7 +56,7 @@ static void listener_cb(short event_mask) { // Add event to the event mask, clients will be notified at the next break of the libwebsockets service loop - events |= event_mask; + websocket_events |= event_mask; } /* @@ -266,7 +266,7 @@ callback_notify(struct lws *wsi, enum lws_callback_reasons reason, void *user, v case LWS_CALLBACK_ESTABLISHED: // Initialize session data for new connections memset(session_data, 0, sizeof(struct ws_session_data_notify)); - session_data->counter = write_events_counter; + session_data->counter = websocket_write_events_counter; break; case LWS_CALLBACK_RECEIVE: @@ -274,10 +274,10 @@ callback_notify(struct lws *wsi, enum lws_callback_reasons reason, void *user, v break; case LWS_CALLBACK_SERVER_WRITEABLE: - if (write_events && (write_events_counter != session_data->counter)) + if (websocket_write_events && (websocket_write_events_counter != session_data->counter)) { - send_notify_reply(write_events, wsi); - session_data->counter = write_events_counter; + send_notify_reply(websocket_write_events, wsi); + session_data->counter = websocket_write_events_counter; } break; @@ -323,14 +323,14 @@ websocket(void *arg) listener_add(listener_cb, LISTENER_UPDATE | LISTENER_DATABASE | LISTENER_PAIRING | LISTENER_SPOTIFY | LISTENER_LASTFM | LISTENER_SPEAKER | LISTENER_PLAYER | LISTENER_OPTIONS | LISTENER_VOLUME | LISTENER_QUEUE); - while(!ws_exit) + while(!websocket_exit) { lws_service(context, 1000); - if (events) + if (websocket_events) { - write_events = events; - write_events_counter++; - events = 0; + websocket_write_events = websocket_events; + websocket_write_events_counter++; + websocket_events = 0; lws_callback_on_writable_all_protocol(context, &protocols[WS_PROTOCOL_NOTIFY]); } } @@ -407,7 +407,7 @@ websocket_init(void) return -1; } - write_events_counter = 0; + websocket_write_events_counter = 0; ret = pthread_create(&tid_websocket, NULL, websocket, NULL); if (ret < 0) { @@ -425,7 +425,7 @@ websocket_deinit(void) { if (websocket_port > 0) { - ws_exit = true; + websocket_exit = true; pthread_join(tid_websocket, NULL); } }