size_t wbio_pos;
};
-
static int
http_client_redirected ( http_client_t *hc );
static int
http_client_testsuite_run( void );
#endif
-
/*
* Global state
*/
return hc->hc_id;
}
+/*
+ *
+ */
+static void
+http_client_get( http_client_t *hc )
+{
+ hc->hc_refcnt++;
+}
+
+static void
+http_client_put( http_client_t *hc )
+{
+ hc->hc_refcnt--;
+}
+
+static int
+http_client_busy( http_client_t *hc )
+{
+ return !!hc->hc_refcnt;
+}
+
/*
*
*/
}
if (hc->hc_fd >= 0) {
if (hc->hc_conn_closed) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
hc->hc_conn_closed(hc, -hc->hc_result);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
}
if (hc->hc_fd >= 0)
close(hc->hc_fd);
tvhtrace(LS_HTTPC, "%04X: finishing", shortid(hc));
if (hc->hc_in_rtp_data && hc->hc_rtp_data_complete) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
res = hc->hc_rtp_data_complete(hc);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
if (res < 0)
return http_client_flush(hc, res);
} else if (hc->hc_data_complete) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
res = hc->hc_data_complete(hc);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
if (res < 0)
return http_client_flush(hc, res);
}
int res;
if (hc->hc_data_received) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
res = hc->hc_data_received(hc, buf, len);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
if (res < 0)
return res;
} else {
if (p)
hc->hc_chunked = strcasecmp(p, "chunked") == 0;
if (hc->hc_hdr_received) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
res = hc->hc_hdr_received(hc);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
if (res < 0)
return http_client_flush(hc, res);
}
return HTTP_CON_RECEIVING;
}
if (hc->hc_rtp_data_received) {
+ http_client_get(hc);
pthread_mutex_unlock(&hc->hc_mutex);
res = hc->hc_rtp_data_received(hc, hc->hc_rbuf + r, hc->hc_csize);
pthread_mutex_lock(&hc->hc_mutex);
+ http_client_put(hc);
if (res < 0)
return res;
} else {
tvhpoll_t *efd;
int r;
+ lock_assert(&hc->hc_mutex);
+
if (u->scheme == NULL || u->scheme[0] == '\0' ||
u->host == NULL || u->host[0] == '\0' ||
u->port < 0) {
free(location);
return -EIO;
}
- free(hc->hc_url);
- hc->hc_url = u.raw ? strdup(u.raw) : NULL;
free(location);
r = http_client_simple_reconnect(hc, &u, hc->hc_redirv);
pthread_mutex_unlock(&http_lock);
}
pthread_mutex_lock(&hc->hc_mutex);
+ while (http_client_busy(hc)) {
+ pthread_mutex_unlock(&hc->hc_mutex);
+ tvh_safe_usleep(10000);
+ pthread_mutex_lock(&hc->hc_mutex);
+ }
http_client_shutdown(hc, 1, 0);
http_client_flush(hc, 0);
tvhtrace(LS_HTTPC, "%04X: Closed", shortid(hc));