Skip to content

Commit

Permalink
http: handle lws_send_pipe_choked state
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jun 23, 2019
1 parent afadc00 commit 9b0166b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, voi
struct pss_http *pss = (struct pss_http *) user;
unsigned char buffer[4096 + LWS_PRE], *p, *end;
char buf[256];
bool done = false;

switch (reason) {
case LWS_CALLBACK_HTTP:
Expand Down Expand Up @@ -164,17 +165,26 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, voi
} else if (m != -1 && m < n) {
n = m;
}
if (pss->ptr + n > pss->buffer + pss->len)
if (pss->ptr + n > pss->buffer + pss->len) {
n = (int) (pss->len - (pss->ptr - pss->buffer));
done = true;
}
memcpy(buffer + LWS_PRE, pss->ptr, n);
pss->ptr += n;
if (lws_write_http(wsi, buffer + LWS_PRE, (size_t) n) < n) {
if (pss->buffer != (char *) index_html) free(pss->buffer);
return -1;
}
} while (!lws_send_pipe_choked(wsi) && pss->ptr != pss->buffer + pss->len);
} while (!lws_send_pipe_choked(wsi) && !done);

if (!done && pss->ptr < pss->buffer + pss->len) {
lws_callback_on_writable(wsi);
break;
}

if (pss->buffer != (char *) index_html) free(pss->buffer);
if (pss->buffer != (char *) index_html) {
free(pss->buffer);
}
goto try_to_reuse;

case LWS_CALLBACK_HTTP_FILE_COMPLETION:
Expand Down

0 comments on commit 9b0166b

Please sign in to comment.