Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/roles/ws/ops-ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,15 @@
#endif
}

#define SANITY_READS (10)
static int
rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi,
struct lws_pollfd *pollfd)
{
unsigned int pending = 0;
struct lws_tokens ebuf;
char buffered = 0;
int n = 0, m, sanity = 10;
int n = 0, m, sanity = SANITY_READS, zero_len_reads = 0;

Check warning on line 953 in lib/roles/ws/ops-ws.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define each identifier in a dedicated statement.

See more on https://sonarcloud.io/project/issues?id=warmcat_libwebsockets&issues=AZ7QMffx-5iz9GRiI4BZ&open=AZ7QMffx-5iz9GRiI4BZ&pullRequest=3187
#if defined(LWS_WITH_HTTP2)
struct lws *wsi1;
#endif
Expand Down Expand Up @@ -1193,6 +1194,7 @@
/* we closed wsi */
return LWS_HPI_RET_WSI_ALREADY_DIED;
}
if (n == 0) zero_len_reads++;
//lws_buflist_describe(&wsi->buflist, wsi, __func__);
//lwsl_notice("%s: consuming %d / %d\n", __func__, n, ebuf.len);
if (ebuf.len < 0 ||
Expand Down Expand Up @@ -1234,7 +1236,7 @@
while (wsi->ws->rx_draining_ext) {
// RX Extension needs to be drained before next read
n = lws_ws_rx_sm(wsi, ALREADY_PROCESSED_IGNORE_CHAR, 0);
if (n < 0) {

Check failure on line 1239 in lib/roles/ws/ops-ws.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=warmcat_libwebsockets&issues=AZ7QMffx-5iz9GRiI4BY&open=AZ7QMffx-5iz9GRiI4BY&pullRequest=3187
return LWS_HPI_RET_PLEASE_CLOSE_ME;
}
}
Expand All @@ -1246,7 +1248,7 @@
* Something has gone wrong, we are spinning...
* let's bail on this connection
*/
return LWS_HPI_RET_PLEASE_CLOSE_ME;
return zero_len_reads == SANITY_READS ? LWS_HPI_RET_PLEASE_CLOSE_ME : LWS_HPI_RET_HANDLED;
}

if (buffered && /* were draining, now nothing left */
Expand All @@ -1265,7 +1267,7 @@
}


int rops_handle_POLLOUT_ws(struct lws *wsi)

Check failure on line 1270 in lib/roles/ws/ops-ws.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 47 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=warmcat_libwebsockets&issues=AZ7QMffx-5iz9GRiI4Ba&open=AZ7QMffx-5iz9GRiI4Ba&pullRequest=3187
{
int write_type = LWS_WRITE_PONG;
#if !defined(LWS_WITHOUT_EXTENSIONS)
Expand Down