Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
httpc: add hc_pause + http_client_unpause() functionality
  • Loading branch information
perexg committed Nov 13, 2015
1 parent c0206a1 commit 8511bd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/http.h
Expand Up @@ -275,6 +275,7 @@ struct http_client {
char *hc_bindaddr;
tvhpoll_t *hc_efd;
int hc_pevents;
int hc_pevents_pause;

int hc_code;
http_ver_t hc_version;
Expand Down Expand Up @@ -316,6 +317,7 @@ struct http_client {
int hc_running:1;
int hc_shutdown_wait:1;
int hc_handle_location:1; /* handle the redirection (location) requests */
int hc_pause:1;

http_client_wcmd_t *hc_wcmd;
TAILQ_HEAD(,http_client_wcmd) hc_wqueue;
Expand Down Expand Up @@ -375,6 +377,7 @@ int http_client_simple( http_client_t *hc, const url_t *url);
int http_client_clear_state( http_client_t *hc );
int http_client_run( http_client_t *hc );
void http_client_ssl_peer_verify( http_client_t *hc, int verify );
void http_client_unpause( http_client_t *hc );

/*
* RTSP helpers
Expand Down
38 changes: 31 additions & 7 deletions src/httpc.c
Expand Up @@ -168,19 +168,39 @@ static void
http_client_poll_dir ( http_client_t *hc, int in, int out )
{
int events = (in ? TVHPOLL_IN : 0) | (out ? TVHPOLL_OUT : 0);
if (hc->hc_efd && hc->hc_pevents != events) {
tvhpoll_event_t ev;
memset(&ev, 0, sizeof(ev));
ev.fd = hc->hc_fd;
ev.events = events | TVHPOLL_IN;
ev.data.ptr = hc;
tvhpoll_add(hc->hc_efd, &ev, 1);
tvhpoll_event_t ev;
if (hc->hc_efd) {
if (events == 0 && hc->hc_pause) {
if (hc->hc_pevents_pause == 0)
hc->hc_pevents_pause = hc->hc_pevents;
memset(&ev, 0, sizeof(ev));
ev.fd = hc->hc_fd;
ev.data.ptr = hc;
tvhpoll_rem(hc->hc_efd, &ev, 1);
} else if (hc->hc_pevents != events) {
memset(&ev, 0, sizeof(ev));
ev.fd = hc->hc_fd;
ev.events = events | TVHPOLL_IN;
ev.data.ptr = hc;
tvhpoll_add(hc->hc_efd, &ev, 1);
}
}
hc->hc_pevents = events;
/* make sure to se the correct errno for our SSL routines */
errno = EAGAIN;
}

void
http_client_unpause( http_client_t *hc )
{
if (hc->hc_pause) {
http_client_poll_dir(hc, hc->hc_pevents_pause & TVHPOLL_IN,
hc->hc_pevents_pause & TVHPOLL_OUT);
hc->hc_pause = 0;
hc->hc_pevents_pause = 0;
}
}

static void
http_client_direction ( http_client_t *hc, int sending )
{
Expand Down Expand Up @@ -909,6 +929,10 @@ http_client_run( http_client_t *hc )
}

retry:
if (hc->hc_pause) {
http_client_poll_dir(hc, 0, 0);
return HTTP_CON_RECEIVING;
}
if (hc->hc_ssl)
r = http_client_ssl_recv(hc, buf, hc->hc_io_size);
else
Expand Down

0 comments on commit 8511bd0

Please sign in to comment.