From: Andy Green Date: Thu, 18 May 2017 15:20:12 +0000 (+0800) Subject: cgi: handle no body to keep events coming X-Git-Tag: accepted/tizen/4.0/unified/20171012.191640~106 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6a68785f7b7468a38e49bb52965c68e178f4154;p=platform%2Fupstream%2Flibwebsockets.git cgi: handle no body to keep events coming --- diff --git a/lib/context.c b/lib/context.c index e9945c7..e1d8479 100644 --- a/lib/context.c +++ b/lib/context.c @@ -241,7 +241,10 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (lws_cgi_write_split_stdout_headers(wsi) < 0) return -1; - wsi->reason_bf &= ~1; + if (wsi->reason_bf & 8) + wsi->reason_bf &= ~8; + else + wsi->reason_bf &= ~1; break; } #endif diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 0e914f3..8781eec 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -2590,10 +2590,15 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) /* finalize cached headers before dumping them */ if (lws_finalize_http_header(wsi, (unsigned char **)&wsi->cgi->headers_pos, - (unsigned char *)wsi->cgi->headers_end)) + (unsigned char *)wsi->cgi->headers_end)) { + + lwsl_notice("finalize failed\n"); return -1; + } wsi->hdr_state = LHCS_DUMP_HEADERS; + wsi->reason_bf |= 8; + lws_callback_on_writable(wsi); /* back to the loop for writeability again */ return 0; @@ -2613,6 +2618,9 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) if (wsi->cgi->headers_dumped == wsi->cgi->headers_pos) { wsi->hdr_state = LHCS_PAYLOAD; lws_free_set_NULL(wsi->cgi->headers_buf); + } else { + wsi->reason_bf |= 8; + lws_callback_on_writable(wsi); } /* writeability becomes uncertain now we wrote @@ -2873,6 +2881,10 @@ lws_cgi_kill_terminated(struct lws_context_per_thread *pt) if (cgi->pid <= 0) continue; + /* finish sending cached headers */ + if (cgi->headers_buf) + continue; + /* wait for stdout to be drained */ if (cgi->content_length > cgi->content_length_seen) continue; @@ -2939,6 +2951,10 @@ lws_cgi_kill_terminated(struct lws_context_per_thread *pt) goto finish_him; } + /* finish sending cached headers */ + if (cgi->headers_buf) + continue; + /* wait for stdout to be drained */ if (cgi->content_length > cgi->content_length_seen) continue;