]> 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>
Tue, 12 Sep 2017 06:31:02 +0000 (08:31 +0200)
src/http.c
src/http.h

index 0ba48b0521940b48bb8b56285185e26bd91733ce..15d74740cd22e653263431f5127b504cc35bfe5d 100644 (file)
@@ -807,8 +807,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,
@@ -822,6 +828,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) {
@@ -860,13 +867,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 c64ec9d1dda1c9a1408ab287c1237bf2fb4e067b..d259b1a171710c4205544f2f33af85bfdc290dbc 100644 (file)
@@ -233,9 +233,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)