1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

http: defer transaction completed if partial pending

This is only helpful for http/1... the real solution is cut up
sending large things.
This commit is contained in:
Andy Green 2018-06-16 10:38:17 +08:00
parent df1d60fc1a
commit d84aebd43a
4 changed files with 38 additions and 0 deletions

View file

@ -126,6 +126,18 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
lwsl_info("** %p signalling to close now\n", wsi);
return -1; /* retry closing now */
}
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
#if !defined(LWS_WITHOUT_SERVER)
if (wsi->http.deferred_transaction_completed) {
lwsl_notice("%s: partial completed, doing "
"deferred transaction completed\n",
__func__);
wsi->http.deferred_transaction_completed = 0;
return lws_http_transaction_completed(wsi);
}
#endif
#endif
}
/* always callback on writeable */
lws_callback_on_writable(wsi);

View file

@ -449,6 +449,16 @@ try_pollout:
if (lwsi_state(wsi) != LRS_ISSUING_FILE) {
if (wsi->trunc_len) {
//lwsl_notice("%s: completing partial\n", __func__);
if (lws_issue_raw(wsi, wsi->trunc_alloc + wsi->trunc_offset,
wsi->trunc_len) < 0) {
lwsl_info("%s signalling to close\n", __func__);
goto fail;
}
return LWS_HPI_RET_HANDLED;
}
lws_stats_atomic_bump(wsi->context, pt,
LWSSTATS_C_WRITEABLE_CB, 1);
#if defined(LWS_WITH_STATS)

View file

@ -227,6 +227,7 @@ struct _lws_http_mode_related {
#if defined(LWS_WITH_HTTP_PROXY)
unsigned int perform_rewrite:1;
#endif
unsigned int deferred_transaction_completed:1;
};

View file

@ -1635,6 +1635,21 @@ lws_http_transaction_completed(struct lws *wsi)
{
int n = NO_PENDING_TIMEOUT;
if (wsi->trunc_len) {
/*
* ...so he tried to send something large as the http reply,
* it went as a partial, but he immediately said the
* transaction was completed.
*
* Defer the transaction completed until the last part of the
* partial is sent.
*/
lwsl_notice("%s: deferring due to partial\n", __func__);
wsi->http.deferred_transaction_completed = 1;
return 0;
}
lwsl_info("%s: wsi %p\n", __func__, wsi);
lws_access_log(wsi);