From 962b8a7dd2c3124a3683c7ffa73621f72140a7d8 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Thu, 11 May 2017 18:59:45 +0200 Subject: Do multiple FETCH_DATA callbacks from http fetcher instead of just one large callback --- content/fetchers/httplib_kolibri.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'content/fetchers/httplib_kolibri.c') diff --git a/content/fetchers/httplib_kolibri.c b/content/fetchers/httplib_kolibri.c index 6800cab13..3361b0460 100644 --- a/content/fetchers/httplib_kolibri.c +++ b/content/fetchers/httplib_kolibri.c @@ -21,6 +21,7 @@ struct httpfetcher { struct http_msg *handle; struct fetch *owner; bool headercbdone; + unsigned int datalen_cb_done; struct httpfetcher *next; }; @@ -98,7 +99,7 @@ bool init_fetcher(lwc_string *scheme) { return supported_scheme; } - + bool supported_url_check(const struct nsurl *url) { bool supported; lwc_string *url_scheme = nsurl_get_component(url, NSURL_SCHEME); @@ -156,6 +157,7 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, newfetcher->handle = request; newfetcher->headercbdone = false; newfetcher->owner = parent_fetch; + newfetcher->datalen_cb_done = 0; return newfetcher; } @@ -296,19 +298,36 @@ void poll_fetch(lwc_string *scheme) { LOG("---- Headers not received yet."); } } + else if(ret == -1) { + /* If data was received send it to netsurf core with FETCH_DATA */ + /* LOG("Doing a data callback; so far : %u vs %u!", t->datalen_cb_done, t->handle->content_received); */ + + if(t->handle->content_received > t->datalen_cb_done) { + fetch_msg msg; + msg.type = FETCH_DATA; + msg.data.header_or_data.buf = (const uint8_t *) (t->handle->content_ptr + t->datalen_cb_done); + msg.data.header_or_data.len = t->handle->content_received - t->datalen_cb_done; + fetch_send_callback(&msg, t->owner); + t->datalen_cb_done = t->handle->content_received; + } + } else if(ret == 0) { - fetch_msg msg; - msg.type = FETCH_DATA; - msg.data.header_or_data.buf = (const uint8_t *)t->handle->content_ptr; - msg.data.header_or_data.len = t->handle->content_length; - fetch_send_callback(&msg, t->owner); - - LOG("---- FETCH_FINISHED for fetch 0x%x", t->owner); + if(t->handle->content_received > t->datalen_cb_done) { + /* Callback any remaining data before finishing off */ + fetch_msg msg; + msg.type = FETCH_DATA; + msg.data.header_or_data.buf = (const uint8_t *) (t->handle->content_ptr + t->datalen_cb_done); + msg.data.header_or_data.len = t->handle->content_received - t->datalen_cb_done; + fetch_send_callback(&msg, t->owner); + t->datalen_cb_done = t->handle->content_received; + } + fetch_msg msg; msg.type = FETCH_FINISHED; msg.data.header_or_data.buf = NULL; msg.data.header_or_data.len = 0; fetch_send_callback(&msg, t->owner); + LOG("---- FETCH_FINISHED for fetch 0x%x", t->owner); struct httpfetcher *tnext = t->next; remove_from_poll(t->handle); -- cgit v1.2.3