]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http: fix extra data (for SAT>IP TCP data mode), issue #4573
authorJaroslav Kysela <perex@perex.cz>
Tue, 12 Sep 2017 06:30:55 +0000 (08:30 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 18 Sep 2017 13:14:01 +0000 (15:14 +0200)
src/http.c
src/http.h

index c99aa1b07640bee2d3053d091b52357aad691ac4..4423299bbc17d6fa8ca9732917712e6001dd5941 100644 (file)
@@ -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;
 }
index 4eb7546a89cb7886bc2f61c82c2e8e74fb7420f5..4dd9ee02079c59c5a5279e1e3ca8e24b595731e8 100644 (file)
@@ -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)