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,
hd->hd_data_off += r;
hc->hc_extra.hq_size -= r;
}
+unlock:
pthread_mutex_unlock(&hc->hc_extra_lock);
if (r < 0) {
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;
}
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)