From: Jaroslav Kysela Date: Tue, 12 Sep 2017 06:30:55 +0000 (+0200) Subject: http: fix extra data (for SAT>IP TCP data mode), issue #4573 X-Git-Tag: v4.2.4~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a1422645a837b8481865dda74c4d617ecd8fe1f;p=thirdparty%2Ftvheadend.git http: fix extra data (for SAT>IP TCP data mode), issue #4573 --- diff --git a/src/http.c b/src/http.c index c99aa1b07..4423299bb 100644 --- a/src/http.c +++ b/src/http.c @@ -722,8 +722,14 @@ http_extra_flush(http_connection_t *hc) goto fin; while (1) { + r = -1; + serr = 0; pthread_mutex_lock(&hc->hc_extra_lock); + if (atomic_add(&hc->hc_extra_insend, 0) != 1) + goto unlock; hd = TAILQ_FIRST(&hc->hc_extra.hq_q); + if (hd == NULL) + goto unlock; do { r = send(hc->hc_fd, hd->hd_data + hd->hd_data_off, hd->hd_data_size - hd->hd_data_off, @@ -737,6 +743,7 @@ http_extra_flush(http_connection_t *hc) hd->hd_data_off += r; hc->hc_extra.hq_size -= r; } +unlock: pthread_mutex_unlock(&hc->hc_extra_lock); if (r < 0) { @@ -775,13 +782,10 @@ http_extra_flush_partial(http_connection_t *hc) htsbuf_data_free(&hc->hc_extra, hd); } pthread_mutex_unlock(&hc->hc_extra_lock); - if (data == NULL) - goto finish; - - r = tvh_write(hc->hc_fd, data + off, size - off); - free(data); - -finish: + if (data) { + r = tvh_write(hc->hc_fd, data + off, size - off); + free(data); + } atomic_dec(&hc->hc_extra_insend, 1); return r; } diff --git a/src/http.h b/src/http.h index 4eb7546a8..4dd9ee020 100644 --- a/src/http.h +++ b/src/http.h @@ -221,9 +221,9 @@ int http_extra_send_prealloc(http_connection_t *hc, const void *data, size_t dat static inline void http_send_begin(http_connection_t *hc) { + atomic_add(&hc->hc_extra_insend, 1); if (atomic_get(&hc->hc_extra_chunks) > 0) http_extra_flush_partial(hc); - atomic_add(&hc->hc_extra_insend, 1); } static inline void http_send_end(http_connection_t *hc)