|
@@ -1759,20 +1759,15 @@ static int inflate_trunc(const unsigned char *src, unsigned int len,
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* ---- headless fetch helper ------------------------------------------- *
|
|
|
|
|
|
|
+/* ---- headless fetch workers ------------------------------------------ *
|
|
|
*
|
|
*
|
|
|
- * Network I/O runs in a separate ring-3 process (`curl __fetch`): it writes
|
|
|
|
|
- * the raw response and a small metadata file under /share. While it works,
|
|
|
|
|
- * the browser keeps drawing and scrolling its own window, so a slow DNS/TLS
|
|
|
|
|
- * handshake or a multi-megabyte body never freezes the UI.
|
|
|
|
|
|
|
+ * Network I/O runs in separate ring-3 processes (`curl __serve <slot>`): each
|
|
|
|
|
+ * writes the raw response, a small metadata file and a done marker under
|
|
|
|
|
+ * /share. Up to FETCH_WORKERS jobs run at once, so a slow DNS/TLS handshake
|
|
|
|
|
+ * or a multi-megabyte body never freezes the UI and images download in
|
|
|
|
|
+ * parallel.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-#define FETCH_REQ "/share/bfreq"
|
|
|
|
|
-#define FETCH_BODY "/share/bfbody"
|
|
|
|
|
-#define FETCH_META "/share/bfmeta"
|
|
|
|
|
-#define FETCH_DONE "/share/bfdone"
|
|
|
|
|
-#define FETCH_POST "/share/bfpost"
|
|
|
|
|
-
|
|
|
|
|
struct fetch_meta {
|
|
struct fetch_meta {
|
|
|
int status;
|
|
int status;
|
|
|
int error;
|
|
int error;
|
|
@@ -1786,8 +1781,35 @@ struct fetch_meta {
|
|
|
static void draw(unsigned int *action);
|
|
static void draw(unsigned int *action);
|
|
|
static void handle_keys(unsigned int *action);
|
|
static void handle_keys(unsigned int *action);
|
|
|
static void handle_page_click(unsigned int *action);
|
|
static void handle_page_click(unsigned int *action);
|
|
|
-static int fetch_helper_tty = -2;
|
|
|
|
|
-static int fetch_helper_pid = -1;
|
|
|
|
|
|
|
+#define FETCH_WORKERS 3
|
|
|
|
|
+#define FETCH_PATH_MAX 32
|
|
|
|
|
+
|
|
|
|
|
+/* One long-lived curl __serve helper per worker. Each worker has its own
|
|
|
|
|
+ * request/body/meta/done files under /share so several downloads can be in
|
|
|
|
|
+ * flight at once; the keep-alive connection stays in the helper process, so
|
|
|
|
|
+ * tls.c's per-process state remains valid. */
|
|
|
|
|
+struct fetch_worker {
|
|
|
|
|
+ int pid;
|
|
|
|
|
+ int slot;
|
|
|
|
|
+ int busy;
|
|
|
|
|
+ int ready;
|
|
|
|
|
+ unsigned int seq;
|
|
|
|
|
+ unsigned int deadline;
|
|
|
|
|
+ int retried;
|
|
|
|
|
+ char req[FETCH_PATH_MAX];
|
|
|
|
|
+ char body[FETCH_PATH_MAX];
|
|
|
|
|
+ char meta[FETCH_PATH_MAX];
|
|
|
|
|
+ char done[FETCH_PATH_MAX];
|
|
|
|
|
+ char post[FETCH_PATH_MAX];
|
|
|
|
|
+ /* Optional preload job attached to this worker. */
|
|
|
|
|
+ unsigned int node;
|
|
|
|
|
+ int bg;
|
|
|
|
|
+ char url[BR_URL_MAX];
|
|
|
|
|
+ struct fetch_meta m;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static struct fetch_worker fetch_workers[FETCH_WORKERS];
|
|
|
|
|
+static int fetch_tty = -2;
|
|
|
static unsigned int fetch_seq;
|
|
static unsigned int fetch_seq;
|
|
|
static struct fetch_meta fetch_meta;
|
|
static struct fetch_meta fetch_meta;
|
|
|
|
|
|
|
@@ -1844,62 +1866,122 @@ static void worker_wait_ui(void)
|
|
|
ngui_end(&ui);
|
|
ngui_end(&ui);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void fetch_helper_stop(void)
|
|
|
|
|
|
|
+static void fetch_path(char *out, unsigned int cap, const char *base, int slot)
|
|
|
{
|
|
{
|
|
|
|
|
+ unsigned int n = 0;
|
|
|
|
|
+
|
|
|
|
|
+ s_append(out, &n, base, cap);
|
|
|
|
|
+ s_append_dec(out, &n, (unsigned int)slot, cap);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void fetch_pool_init(void)
|
|
|
|
|
+{
|
|
|
|
|
+ static int ready;
|
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
- if (fetch_helper_pid > 0) {
|
|
|
|
|
- u_kill((unsigned int)fetch_helper_pid);
|
|
|
|
|
- for (i = 0; i < 40 && u_alive((unsigned int)fetch_helper_pid); i++)
|
|
|
|
|
|
|
+ if (ready)
|
|
|
|
|
+ return;
|
|
|
|
|
+ ready = 1;
|
|
|
|
|
+ for (i = 0; i < FETCH_WORKERS; i++) {
|
|
|
|
|
+ struct fetch_worker *w = &fetch_workers[i];
|
|
|
|
|
+
|
|
|
|
|
+ w->pid = -1;
|
|
|
|
|
+ w->slot = i;
|
|
|
|
|
+ fetch_path(w->req, sizeof(w->req), "/share/bfreq", i);
|
|
|
|
|
+ fetch_path(w->body, sizeof(w->body), "/share/bfbody", i);
|
|
|
|
|
+ fetch_path(w->meta, sizeof(w->meta), "/share/bfmeta", i);
|
|
|
|
|
+ fetch_path(w->done, sizeof(w->done), "/share/bfdone", i);
|
|
|
|
|
+ fetch_path(w->post, sizeof(w->post), "/share/bfpost", i);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void fetch_worker_stop(struct fetch_worker *w)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ if (w->pid > 0) {
|
|
|
|
|
+ u_kill((unsigned int)w->pid);
|
|
|
|
|
+ for (i = 0; i < 40 && u_alive((unsigned int)w->pid); i++)
|
|
|
u_sleep_ms(5);
|
|
u_sleep_ms(5);
|
|
|
- /* Let the reaper release the NIC before the next request. */
|
|
|
|
|
|
|
+ /* Let the reaper close the socket before we reuse the slot. */
|
|
|
u_sleep_ms(10);
|
|
u_sleep_ms(10);
|
|
|
}
|
|
}
|
|
|
- fetch_helper_pid = -1;
|
|
|
|
|
|
|
+ w->pid = -1;
|
|
|
|
|
+ w->busy = 0;
|
|
|
|
|
+ w->ready = 0;
|
|
|
|
|
+ if (w->req[0]) {
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->done);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->meta);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->body);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->post);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->req);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void fetch_workers_stop_all(void)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < FETCH_WORKERS; i++)
|
|
|
|
|
+ fetch_worker_stop(&fetch_workers[i]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int fetch_helper_start(char *err, unsigned int errcap)
|
|
|
|
|
|
|
+static int fetch_worker_start(struct fetch_worker *w, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
{
|
|
{
|
|
|
- if (fetch_helper_pid > 0 &&
|
|
|
|
|
- u_alive((unsigned int)fetch_helper_pid))
|
|
|
|
|
|
|
+ char arg[24];
|
|
|
|
|
+ unsigned int n = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (w->pid > 0 && u_alive((unsigned int)w->pid))
|
|
|
return 0;
|
|
return 0;
|
|
|
- fetch_helper_pid = -1;
|
|
|
|
|
- if (fetch_helper_tty == -2) {
|
|
|
|
|
|
|
+ w->pid = -1;
|
|
|
|
|
+ fetch_pool_init();
|
|
|
|
|
+ if (fetch_tty == -2) {
|
|
|
int t = u_tty_create();
|
|
int t = u_tty_create();
|
|
|
|
|
|
|
|
- fetch_helper_tty = t > 0 ? t : 0;
|
|
|
|
|
|
|
+ fetch_tty = t > 0 ? t : 0;
|
|
|
}
|
|
}
|
|
|
- fetch_helper_pid = u_spawn("/ramfs/bin/curl", "__serve",
|
|
|
|
|
- fetch_helper_tty, "/");
|
|
|
|
|
- if (fetch_helper_pid <= 0) {
|
|
|
|
|
- fetch_helper_pid = -1;
|
|
|
|
|
|
|
+ s_append(arg, &n, "__serve ", sizeof(arg));
|
|
|
|
|
+ s_append_dec(arg, &n, (unsigned int)w->slot, sizeof(arg));
|
|
|
|
|
+ w->pid = u_spawn("/ramfs/bin/curl", arg, fetch_tty, "/");
|
|
|
|
|
+ if (w->pid <= 0) {
|
|
|
|
|
+ w->pid = -1;
|
|
|
s_copy(err, "cannot start network helper", errcap);
|
|
s_copy(err, "cannot start network helper", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int worker_fetch(const char *url, unsigned int cap,
|
|
|
|
|
- const char *post, unsigned int post_len,
|
|
|
|
|
- struct fetch_meta *m, char *err, unsigned int errcap)
|
|
|
|
|
|
|
+static struct fetch_worker *fetch_worker_alloc(void)
|
|
|
{
|
|
{
|
|
|
- static char req[768], meta[1024], done[24];
|
|
|
|
|
- char *p;
|
|
|
|
|
- unsigned int n = 0, deadline;
|
|
|
|
|
- int rn, mseq, retried = 0;
|
|
|
|
|
- struct sys_stat st;
|
|
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ fetch_pool_init();
|
|
|
|
|
+ for (i = 0; i < FETCH_WORKERS; i++)
|
|
|
|
|
+ if (!fetch_workers[i].busy)
|
|
|
|
|
+ return &fetch_workers[i];
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int fetch_worker_submit(struct fetch_worker *w, const char *url,
|
|
|
|
|
+ unsigned int cap, const char *post,
|
|
|
|
|
+ unsigned int post_len, unsigned int node,
|
|
|
|
|
+ int bg, char *err, unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ static char req[768];
|
|
|
|
|
+ unsigned int n = 0;
|
|
|
|
|
|
|
|
- if (cancel_fetch || pending_action)
|
|
|
|
|
- return FETCH_ABORT;
|
|
|
|
|
- if (u_stat("/share", &st) != 0 || !st.is_dir ||
|
|
|
|
|
- u_stat("/ramfs/bin/curl", &st) != 0) {
|
|
|
|
|
- s_copy(err, "network helper unavailable", errcap);
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
fetch_seq++;
|
|
fetch_seq++;
|
|
|
if (!fetch_seq)
|
|
if (!fetch_seq)
|
|
|
fetch_seq = 1;
|
|
fetch_seq = 1;
|
|
|
- s_append_dec(req, &n, fetch_seq, sizeof(req));
|
|
|
|
|
|
|
+ w->seq = fetch_seq;
|
|
|
|
|
+ w->ready = 0;
|
|
|
|
|
+ w->retried = 0;
|
|
|
|
|
+ w->node = node;
|
|
|
|
|
+ w->bg = bg;
|
|
|
|
|
+ s_copy(w->url, url, sizeof(w->url));
|
|
|
|
|
+
|
|
|
|
|
+ s_append_dec(req, &n, w->seq, sizeof(req));
|
|
|
s_append(req, &n, " ", sizeof(req));
|
|
s_append(req, &n, " ", sizeof(req));
|
|
|
s_append_dec(req, &n, cap, sizeof(req));
|
|
s_append_dec(req, &n, cap, sizeof(req));
|
|
|
s_append(req, &n, " ", sizeof(req));
|
|
s_append(req, &n, " ", sizeof(req));
|
|
@@ -1910,54 +1992,34 @@ static int worker_fetch(const char *url, unsigned int cap,
|
|
|
}
|
|
}
|
|
|
s_append(req, &n, url, sizeof(req));
|
|
s_append(req, &n, url, sizeof(req));
|
|
|
s_append(req, &n, "\n", sizeof(req));
|
|
s_append(req, &n, "\n", sizeof(req));
|
|
|
- if (post_len && u_syscall3(SYS_WRITE_FILE, (int)FETCH_POST,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (post_len && u_syscall3(SYS_WRITE_FILE, (int)w->post,
|
|
|
(int)post, (int)post_len) < 0) {
|
|
(int)post, (int)post_len) < 0) {
|
|
|
s_copy(err, "cannot queue form body", errcap);
|
|
s_copy(err, "cannot queue form body", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- u_syscall1(SYS_UNLINK, (int)FETCH_DONE);
|
|
|
|
|
- u_syscall1(SYS_UNLINK, (int)FETCH_META);
|
|
|
|
|
- if (u_syscall3(SYS_WRITE_FILE, (int)FETCH_REQ, (int)req, (int)n) < 0) {
|
|
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->done);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->meta);
|
|
|
|
|
+ if (u_syscall3(SYS_WRITE_FILE, (int)w->req, (int)req, (int)n) < 0) {
|
|
|
s_copy(err, "cannot queue network request", errcap);
|
|
s_copy(err, "cannot queue network request", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- if (fetch_helper_start(err, errcap) != 0)
|
|
|
|
|
|
|
+ if (fetch_worker_start(w, err, errcap) != 0)
|
|
|
return -1;
|
|
return -1;
|
|
|
- deadline = u_ticks_ms() + UHTTP_TOTAL_TIMEOUT_MS + 5000;
|
|
|
|
|
- for (;;) {
|
|
|
|
|
- worker_wait_ui();
|
|
|
|
|
- if (cancel_fetch || pending_action) {
|
|
|
|
|
- fetch_helper_stop();
|
|
|
|
|
- return FETCH_ABORT;
|
|
|
|
|
- }
|
|
|
|
|
- rn = u_syscall3(SYS_READ_FILE, (int)FETCH_DONE, (int)done,
|
|
|
|
|
- (int)(sizeof(done) - 1));
|
|
|
|
|
- if (rn > 0) {
|
|
|
|
|
- done[rn] = '\0';
|
|
|
|
|
- p = done;
|
|
|
|
|
- mseq = (int)meta_uint(&p);
|
|
|
|
|
- if (mseq == (int)fetch_seq)
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- if (!u_alive((unsigned int)fetch_helper_pid)) {
|
|
|
|
|
- fetch_helper_pid = -1;
|
|
|
|
|
- if (!retried && fetch_helper_start(err, errcap) == 0) {
|
|
|
|
|
- retried = 1;
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- s_copy(err, "network helper stopped", errcap);
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
- if ((int)(u_ticks_ms() - deadline) >= 0) {
|
|
|
|
|
- fetch_helper_stop();
|
|
|
|
|
- s_copy(err, "network request timed out", errcap);
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
- u_sleep_ms(20);
|
|
|
|
|
- }
|
|
|
|
|
- if (cancel_fetch || pending_action)
|
|
|
|
|
- return FETCH_ABORT;
|
|
|
|
|
- rn = u_syscall3(SYS_READ_FILE, (int)FETCH_META, (int)meta,
|
|
|
|
|
|
|
+ w->busy = 1;
|
|
|
|
|
+ w->deadline = u_ticks_ms() + UHTTP_TOTAL_TIMEOUT_MS + 5000;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Read and parse w->meta after w->done matched. Returns 0 when ready. */
|
|
|
|
|
+static int fetch_worker_read_meta(struct fetch_worker *w, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ static char meta[1024];
|
|
|
|
|
+ char *p;
|
|
|
|
|
+ int rn, mseq;
|
|
|
|
|
+
|
|
|
|
|
+ rn = u_syscall3(SYS_READ_FILE, (int)w->meta, (int)meta,
|
|
|
(int)(sizeof(meta) - 1));
|
|
(int)(sizeof(meta) - 1));
|
|
|
if (rn <= 0) {
|
|
if (rn <= 0) {
|
|
|
s_copy(err, "network helper failed", errcap);
|
|
s_copy(err, "network helper failed", errcap);
|
|
@@ -1966,54 +2028,98 @@ static int worker_fetch(const char *url, unsigned int cap,
|
|
|
meta[rn] = '\0';
|
|
meta[rn] = '\0';
|
|
|
p = meta;
|
|
p = meta;
|
|
|
mseq = (int)meta_uint(&p);
|
|
mseq = (int)meta_uint(&p);
|
|
|
- if (mseq != (int)fetch_seq) {
|
|
|
|
|
|
|
+ if (mseq != (int)w->seq) {
|
|
|
s_copy(err, "stale network response", errcap);
|
|
s_copy(err, "stale network response", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- m->status = (int)meta_uint(&p);
|
|
|
|
|
- m->error = (int)meta_uint(&p);
|
|
|
|
|
- m->trunc = (int)meta_uint(&p);
|
|
|
|
|
- meta_str(&p, m->encoding, sizeof(m->encoding));
|
|
|
|
|
- meta_str(&p, m->ctype, sizeof(m->ctype));
|
|
|
|
|
- meta_str(&p, m->final, sizeof(m->final));
|
|
|
|
|
- m->len = meta_uint(&p);
|
|
|
|
|
- if (m->error) {
|
|
|
|
|
- s_copy(err, uhttp_error_string(m->error), errcap);
|
|
|
|
|
|
|
+ w->m.status = (int)meta_uint(&p);
|
|
|
|
|
+ w->m.error = (int)meta_uint(&p);
|
|
|
|
|
+ w->m.trunc = (int)meta_uint(&p);
|
|
|
|
|
+ meta_str(&p, w->m.encoding, sizeof(w->m.encoding));
|
|
|
|
|
+ meta_str(&p, w->m.ctype, sizeof(w->m.ctype));
|
|
|
|
|
+ meta_str(&p, w->m.final, sizeof(w->m.final));
|
|
|
|
|
+ w->m.len = meta_uint(&p);
|
|
|
|
|
+ if (w->m.error) {
|
|
|
|
|
+ s_copy(err, uhttp_error_string(w->m.error), errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
+ w->ready = 1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int fetch_remote(const char *url, unsigned int cap,
|
|
|
|
|
- const char *post, unsigned int post_len,
|
|
|
|
|
- unsigned char *plain, unsigned int plaincap,
|
|
|
|
|
- unsigned char *comp, unsigned int compcap,
|
|
|
|
|
- struct fetch_meta *m, int *truncated,
|
|
|
|
|
- char *err, unsigned int errcap)
|
|
|
|
|
|
|
+/* Non-blocking poll: 1 ready, 0 still running, -1 failed. */
|
|
|
|
|
+static int fetch_worker_poll(struct fetch_worker *w, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
{
|
|
{
|
|
|
- int rv, zr, was_trunc;
|
|
|
|
|
|
|
+ static char done[24];
|
|
|
|
|
+ char *p;
|
|
|
|
|
+ int rn, mseq;
|
|
|
|
|
|
|
|
- rv = worker_fetch(url, cap, post, post_len, m, err, errcap);
|
|
|
|
|
- if (rv == FETCH_ABORT)
|
|
|
|
|
- return FETCH_ABORT;
|
|
|
|
|
- if (rv != 0)
|
|
|
|
|
|
|
+ if (!w->busy)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ if (w->ready)
|
|
|
|
|
+ return 1;
|
|
|
|
|
+
|
|
|
|
|
+ rn = u_syscall3(SYS_READ_FILE, (int)w->done, (int)done,
|
|
|
|
|
+ (int)(sizeof(done) - 1));
|
|
|
|
|
+ if (rn > 0) {
|
|
|
|
|
+ done[rn] = '\0';
|
|
|
|
|
+ p = done;
|
|
|
|
|
+ mseq = (int)meta_uint(&p);
|
|
|
|
|
+ if (mseq == (int)w->seq) {
|
|
|
|
|
+ if (fetch_worker_read_meta(w, err, errcap) != 0) {
|
|
|
|
|
+ fetch_worker_stop(w);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!u_alive((unsigned int)w->pid)) {
|
|
|
|
|
+ w->pid = -1;
|
|
|
|
|
+ if (!w->retried && fetch_worker_start(w, err, errcap) == 0) {
|
|
|
|
|
+ w->retried = 1;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ s_copy(err, "network helper stopped", errcap);
|
|
|
|
|
+ fetch_worker_stop(w);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((int)(u_ticks_ms() - w->deadline) >= 0) {
|
|
|
|
|
+ s_copy(err, "network request timed out", errcap);
|
|
|
|
|
+ fetch_worker_stop(w);
|
|
|
return -1;
|
|
return -1;
|
|
|
- if (contains_ci(m->encoding, "gzip") ||
|
|
|
|
|
- contains_ci(m->encoding, "deflate")) {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Copy the completed body, inflating it if the server ignored our identity
|
|
|
|
|
+ * request. Mirrors the old fetch_remote body path. */
|
|
|
|
|
+static int fetch_worker_read_body(struct fetch_worker *w,
|
|
|
|
|
+ unsigned char *plain,
|
|
|
|
|
+ unsigned int plaincap,
|
|
|
|
|
+ unsigned char *comp,
|
|
|
|
|
+ unsigned int compcap,
|
|
|
|
|
+ int *truncated, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ int rv, zr, was_trunc;
|
|
|
|
|
+
|
|
|
|
|
+ if (contains_ci(w->m.encoding, "gzip") ||
|
|
|
|
|
+ contains_ci(w->m.encoding, "deflate")) {
|
|
|
unsigned int comp_len = 0, plen = 0;
|
|
unsigned int comp_len = 0, plen = 0;
|
|
|
|
|
|
|
|
- rv = u_syscall3(SYS_READ_FILE, (int)FETCH_BODY, (int)comp,
|
|
|
|
|
|
|
+ rv = u_syscall3(SYS_READ_FILE, (int)w->body, (int)comp,
|
|
|
(int)compcap);
|
|
(int)compcap);
|
|
|
if (rv < 0) {
|
|
if (rv < 0) {
|
|
|
s_copy(err, "empty response", errcap);
|
|
s_copy(err, "empty response", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
comp_len = (unsigned int)rv;
|
|
comp_len = (unsigned int)rv;
|
|
|
- if (comp_len < m->len) {
|
|
|
|
|
|
|
+ if (comp_len < w->m.len) {
|
|
|
s_copy(err, "compressed response is too large", errcap);
|
|
s_copy(err, "compressed response is too large", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- if (contains_ci(m->encoding, "deflate"))
|
|
|
|
|
|
|
+ if (contains_ci(w->m.encoding, "deflate"))
|
|
|
zr = inflate_trunc(comp, comp_len, plain, plaincap,
|
|
zr = inflate_trunc(comp, comp_len, plain, plaincap,
|
|
|
&plen, 0, &was_trunc);
|
|
&plen, 0, &was_trunc);
|
|
|
else
|
|
else
|
|
@@ -2023,18 +2129,83 @@ static int fetch_remote(const char *url, unsigned int cap,
|
|
|
s_copy(err, "compressed response is corrupt", errcap);
|
|
s_copy(err, "compressed response is corrupt", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- *truncated = m->trunc || was_trunc;
|
|
|
|
|
- return (cancel_fetch || pending_action) ? FETCH_ABORT :
|
|
|
|
|
- (int)plen;
|
|
|
|
|
|
|
+ *truncated = w->m.trunc || was_trunc;
|
|
|
|
|
+ return (int)plen;
|
|
|
}
|
|
}
|
|
|
- rv = u_syscall3(SYS_READ_FILE, (int)FETCH_BODY, (int)plain,
|
|
|
|
|
- (int)plaincap);
|
|
|
|
|
|
|
+ rv = u_syscall3(SYS_READ_FILE, (int)w->body, (int)plain, (int)plaincap);
|
|
|
if (rv < 0) {
|
|
if (rv < 0) {
|
|
|
s_copy(err, "empty response", errcap);
|
|
s_copy(err, "empty response", errcap);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- *truncated = m->trunc || ((unsigned int)rv < m->len);
|
|
|
|
|
- return (cancel_fetch || pending_action) ? FETCH_ABORT : rv;
|
|
|
|
|
|
|
+ *truncated = w->m.trunc || ((unsigned int)rv < w->m.len);
|
|
|
|
|
+ return rv;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void fetch_worker_release(struct fetch_worker *w)
|
|
|
|
|
+{
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->done);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->meta);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->body);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->post);
|
|
|
|
|
+ u_syscall1(SYS_UNLINK, (int)w->req);
|
|
|
|
|
+ w->busy = 0;
|
|
|
|
|
+ w->ready = 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Blocking wait used by page/CSS/script fetches; keeps the UI alive. */
|
|
|
|
|
+static int fetch_worker_wait(struct fetch_worker *w, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ for (;;) {
|
|
|
|
|
+ int rv;
|
|
|
|
|
+
|
|
|
|
|
+ worker_wait_ui();
|
|
|
|
|
+ if (cancel_fetch || pending_action) {
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ return FETCH_ABORT;
|
|
|
|
|
+ }
|
|
|
|
|
+ rv = fetch_worker_poll(w, err, errcap);
|
|
|
|
|
+ if (rv != 0)
|
|
|
|
|
+ return rv == 1 ? 0 : -1;
|
|
|
|
|
+ u_sleep_ms(20);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int fetch_remote(const char *url, unsigned int cap,
|
|
|
|
|
+ const char *post, unsigned int post_len,
|
|
|
|
|
+ unsigned char *plain, unsigned int plaincap,
|
|
|
|
|
+ unsigned char *comp, unsigned int compcap,
|
|
|
|
|
+ struct fetch_meta *m, int *truncated,
|
|
|
|
|
+ char *err, unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ struct fetch_worker *w = fetch_worker_alloc();
|
|
|
|
|
+ int rv;
|
|
|
|
|
+
|
|
|
|
|
+ if (!w) {
|
|
|
|
|
+ s_copy(err, "network busy", errcap);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fetch_worker_submit(w, url, cap, post, post_len, 0, 0,
|
|
|
|
|
+ err, errcap) != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ rv = fetch_worker_wait(w, err, errcap);
|
|
|
|
|
+ if (rv == FETCH_ABORT) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ return FETCH_ABORT;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rv != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ *m = w->m;
|
|
|
|
|
+ rv = fetch_worker_read_body(w, plain, plaincap, comp, compcap,
|
|
|
|
|
+ truncated, err, errcap);
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ if (rv >= 0 && (cancel_fetch || pending_action))
|
|
|
|
|
+ return FETCH_ABORT;
|
|
|
|
|
+ return rv;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* ---- HTTP / file fetch ---- */
|
|
/* ---- HTTP / file fetch ---- */
|
|
@@ -2522,6 +2693,7 @@ static void show_error(const char *title, const char *detail)
|
|
|
preload_active = 0;
|
|
preload_active = 0;
|
|
|
preload_pending = 0;
|
|
preload_pending = 0;
|
|
|
preload_wait = 0;
|
|
preload_wait = 0;
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
s_copy(page_title, title, sizeof(page_title));
|
|
s_copy(page_title, title, sizeof(page_title));
|
|
|
page_loading = 0;
|
|
page_loading = 0;
|
|
|
set_status(title, 1, 0);
|
|
set_status(title, 1, 0);
|
|
@@ -2663,29 +2835,107 @@ static void style_for_node(unsigned int node, struct br_style *out)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* Load at most one image per call. Images below the current viewport are
|
|
|
|
|
- * left pending until the page is scrolled; this keeps a long article with
|
|
|
|
|
- * many 4K screenshots from stalling on content the user cannot see yet. */
|
|
|
|
|
-static void preload_step(void)
|
|
|
|
|
|
|
+/* ---- parallel image preloading ---- *
|
|
|
|
|
+ *
|
|
|
|
|
+ * Up to FETCH_WORKERS image downloads run in separate curl helpers at once.
|
|
|
|
|
+ * preload_step() only starts jobs and harvests completed ones; the browser
|
|
|
|
|
+ * main loop keeps drawing between calls, instead of blocking on one fetch.
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+static int preload_active_jobs(void)
|
|
|
{
|
|
{
|
|
|
- unsigned int batch = 0;
|
|
|
|
|
|
|
+ int i, n = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < FETCH_WORKERS; i++)
|
|
|
|
|
+ if (fetch_workers[i].busy)
|
|
|
|
|
+ n++;
|
|
|
|
|
+ return n;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void preload_job_error(struct fetch_worker *w)
|
|
|
|
|
+{
|
|
|
|
|
+ if (w->node < doc.nnode) {
|
|
|
|
|
+ if (w->bg)
|
|
|
|
|
+ doc.nodes[w->node].bg_img_index = -2;
|
|
|
|
|
+ else
|
|
|
|
|
+ doc.nodes[w->node].img_index = -2;
|
|
|
|
|
+ ngui_invalidate(&ui);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void preload_decode(unsigned int node, int bg,
|
|
|
|
|
+ const unsigned char *data, unsigned int len)
|
|
|
|
|
+{
|
|
|
|
|
+ if (image_count >= BR_MAX_IMAGES) {
|
|
|
|
|
+ if (bg)
|
|
|
|
|
+ doc.nodes[node].bg_img_index = -2;
|
|
|
|
|
+ else
|
|
|
|
|
+ doc.nodes[node].img_index = -2;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (decode_image_data(data, len, &images[image_count]) == 0) {
|
|
|
|
|
+ if (bg)
|
|
|
|
|
+ doc.nodes[node].bg_img_index = (short)image_count;
|
|
|
|
|
+ else
|
|
|
|
|
+ doc.nodes[node].img_index = (short)image_count;
|
|
|
|
|
+ image_count++;
|
|
|
|
|
+ preload_loaded++;
|
|
|
|
|
+ layout_valid = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (bg)
|
|
|
|
|
+ doc.nodes[node].bg_img_index = -2;
|
|
|
|
|
+ else
|
|
|
|
|
+ doc.nodes[node].img_index = -2;
|
|
|
|
|
+ }
|
|
|
|
|
+ ngui_invalidate(&ui);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Harvest one completed worker. Returns 1 when a job was finished. */
|
|
|
|
|
+static int preload_finish_worker(struct fetch_worker *w)
|
|
|
|
|
+{
|
|
|
|
|
+ char err[64];
|
|
|
|
|
+ int rv, tr = 0;
|
|
|
|
|
+
|
|
|
|
|
+ rv = fetch_worker_poll(w, err, sizeof(err));
|
|
|
|
|
+ if (rv < 0) {
|
|
|
|
|
+ preload_job_error(w);
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rv == 0)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ rv = fetch_worker_read_body(w, image_file_buf, BR_IMG_FILE_MAX,
|
|
|
|
|
+ image_comp_buf, BR_IMG_FILE_MAX,
|
|
|
|
|
+ &tr, err, sizeof(err));
|
|
|
|
|
+ if (rv >= 0)
|
|
|
|
|
+ preload_decode(w->node, w->bg, image_file_buf,
|
|
|
|
|
+ (unsigned int)rv);
|
|
|
|
|
+ else
|
|
|
|
|
+ preload_job_error(w);
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Fill free workers from the DOM, scanning past ineligible nodes. Returns
|
|
|
|
|
+ * the number of jobs started. */
|
|
|
|
|
+static int preload_fill_jobs(void)
|
|
|
|
|
+{
|
|
|
|
|
+ int started = 0;
|
|
|
|
|
+ char err[64];
|
|
|
|
|
|
|
|
while (preload_active && preload_node < doc.nnode) {
|
|
while (preload_active && preload_node < doc.nnode) {
|
|
|
unsigned int i = preload_node;
|
|
unsigned int i = preload_node;
|
|
|
struct br_node *nd = &doc.nodes[i];
|
|
struct br_node *nd = &doc.nodes[i];
|
|
|
const char *src;
|
|
const char *src;
|
|
|
char url[BR_URL_MAX];
|
|
char url[BR_URL_MAX];
|
|
|
- unsigned char *data;
|
|
|
|
|
- unsigned int len;
|
|
|
|
|
- char err[64];
|
|
|
|
|
- char msg[64];
|
|
|
|
|
- unsigned int n = 0;
|
|
|
|
|
- int rv;
|
|
|
|
|
|
|
+ struct fetch_worker *w;
|
|
|
|
|
|
|
|
if (nd->type != BR_NODE_ELEM) {
|
|
if (nd->type != BR_NODE_ELEM) {
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (nd->tag != BR_TAG_IMG) {
|
|
if (nd->tag != BR_TAG_IMG) {
|
|
|
if (nd->bg_img_index == -1) {
|
|
if (nd->bg_img_index == -1) {
|
|
|
struct br_style bs;
|
|
struct br_style bs;
|
|
@@ -2701,39 +2951,41 @@ static void preload_step(void)
|
|
|
!starts_with(bsrc, "data:") &&
|
|
!starts_with(bsrc, "data:") &&
|
|
|
resolve_link(page_url, bsrc, url,
|
|
resolve_link(page_url, bsrc, url,
|
|
|
sizeof(url)) == 0) {
|
|
sizeof(url)) == 0) {
|
|
|
- if (image_count >=
|
|
|
|
|
|
|
+ if (image_count +
|
|
|
|
|
+ preload_active_jobs() >=
|
|
|
BR_MAX_IMAGES) {
|
|
BR_MAX_IMAGES) {
|
|
|
- preload_node =
|
|
|
|
|
- doc.nnode;
|
|
|
|
|
|
|
+ preload_node = doc.nnode;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- preload_node = i + 1;
|
|
|
|
|
- data = 0;
|
|
|
|
|
- len = 0;
|
|
|
|
|
- rv = fetch_image(url,
|
|
|
|
|
- BR_IMG_FILE_MAX,
|
|
|
|
|
- &data, &len,
|
|
|
|
|
- err, sizeof(err));
|
|
|
|
|
- if (rv == FETCH_ABORT) {
|
|
|
|
|
- preload_active = 0;
|
|
|
|
|
- preload_pending = 0;
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (url[0] == '/') {
|
|
|
|
|
+ unsigned char *data = 0;
|
|
|
|
|
+ unsigned int len = 0;
|
|
|
|
|
+
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ if (fetch_image(url,
|
|
|
|
|
+ BR_IMG_FILE_MAX,
|
|
|
|
|
+ &data, &len,
|
|
|
|
|
+ err,
|
|
|
|
|
+ sizeof(err)) == 0)
|
|
|
|
|
+ preload_decode(i, 1, data, len);
|
|
|
|
|
+ else
|
|
|
|
|
+ nd->bg_img_index = -2;
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (rv == 0 &&
|
|
|
|
|
- decode_image_data(
|
|
|
|
|
- data, len,
|
|
|
|
|
- &images[image_count]) == 0) {
|
|
|
|
|
- nd->bg_img_index =
|
|
|
|
|
- (short)image_count;
|
|
|
|
|
- image_count++;
|
|
|
|
|
- preload_loaded++;
|
|
|
|
|
- layout_valid = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ return started;
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ if (fetch_worker_submit(w, url,
|
|
|
|
|
+ BR_IMG_FILE_MAX,
|
|
|
|
|
+ 0, 0, i, 1,
|
|
|
|
|
+ err,
|
|
|
|
|
+ sizeof(err)) != 0) {
|
|
|
nd->bg_img_index = -2;
|
|
nd->bg_img_index = -2;
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- ngui_invalidate(&ui);
|
|
|
|
|
- if (++batch >= 4)
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ started++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2742,6 +2994,7 @@ static void preload_step(void)
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (nd->img_index != -1) {
|
|
if (nd->img_index != -1) {
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
@@ -2760,7 +3013,7 @@ static void preload_step(void)
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- if (image_count >= BR_MAX_IMAGES) {
|
|
|
|
|
|
|
+ if (image_count + preload_active_jobs() >= BR_MAX_IMAGES) {
|
|
|
preload_node = doc.nnode;
|
|
preload_node = doc.nnode;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -2773,51 +3026,90 @@ static void preload_step(void)
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- preload_node = i + 1;
|
|
|
|
|
|
|
|
|
|
- s_append(msg, &n, "Loading images ", sizeof(msg));
|
|
|
|
|
- s_append_dec(msg, &n, (unsigned int)preload_loaded + 1,
|
|
|
|
|
- sizeof(msg));
|
|
|
|
|
- s_append(msg, &n, "...", sizeof(msg));
|
|
|
|
|
- set_status(msg, 0, 0);
|
|
|
|
|
- ngui_invalidate(&ui);
|
|
|
|
|
|
|
+ if (url[0] == '/') {
|
|
|
|
|
+ unsigned char *data = 0;
|
|
|
|
|
+ unsigned int len = 0;
|
|
|
|
|
|
|
|
- data = 0;
|
|
|
|
|
- len = 0;
|
|
|
|
|
- rv = fetch_image(url, BR_IMG_FILE_MAX, &data, &len, err,
|
|
|
|
|
- sizeof(err));
|
|
|
|
|
- if (rv == FETCH_ABORT) {
|
|
|
|
|
- preload_active = 0;
|
|
|
|
|
- preload_pending = 0;
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ if (fetch_image(url, BR_IMG_FILE_MAX, &data, &len,
|
|
|
|
|
+ err, sizeof(err)) == 0)
|
|
|
|
|
+ preload_decode(i, 0, data, len);
|
|
|
|
|
+ else
|
|
|
|
|
+ nd->img_index = -2;
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (rv == 0 &&
|
|
|
|
|
- decode_image_data(data, len, &images[image_count]) == 0) {
|
|
|
|
|
- nd->img_index = (short)image_count;
|
|
|
|
|
- image_count++;
|
|
|
|
|
- preload_loaded++;
|
|
|
|
|
- layout_valid = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
- /* Remember failures so a scroll does not retry an
|
|
|
|
|
- * unreachable tracking/ad image with the full network
|
|
|
|
|
- * timeout on every pass. */
|
|
|
|
|
|
|
+
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ return started;
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ {
|
|
|
|
|
+ char msg[64];
|
|
|
|
|
+ unsigned int n = 0;
|
|
|
|
|
+
|
|
|
|
|
+ s_append(msg, &n, "Loading images ", sizeof(msg));
|
|
|
|
|
+ s_append_dec(msg, &n,
|
|
|
|
|
+ (unsigned int)preload_loaded + 1,
|
|
|
|
|
+ sizeof(msg));
|
|
|
|
|
+ s_append(msg, &n, "...", sizeof(msg));
|
|
|
|
|
+ set_status(msg, 0, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fetch_worker_submit(w, url, BR_IMG_FILE_MAX, 0, 0, i, 0,
|
|
|
|
|
+ err, sizeof(err)) != 0) {
|
|
|
nd->img_index = -2;
|
|
nd->img_index = -2;
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- ngui_invalidate(&ui);
|
|
|
|
|
- /* A full page layout after every image dominates loading on a
|
|
|
|
|
- * long page. Decode a small batch, then let the main loop draw
|
|
|
|
|
- * once for the whole batch. */
|
|
|
|
|
- if (++batch >= 4)
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ started++;
|
|
|
}
|
|
}
|
|
|
|
|
+ return started;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- preload_active = 0;
|
|
|
|
|
- if (preload_pending)
|
|
|
|
|
- preload_scroll = page_scroll.offset;
|
|
|
|
|
- else
|
|
|
|
|
|
|
+static void preload_step(void)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int batch = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (!preload_active)
|
|
|
|
|
+ return;
|
|
|
|
|
+ if (cancel_fetch || pending_action) {
|
|
|
|
|
+ preload_active = 0;
|
|
|
preload_pending = 0;
|
|
preload_pending = 0;
|
|
|
- set_status(post_status_text, post_status_error, post_status_ttl);
|
|
|
|
|
- ngui_invalidate(&ui);
|
|
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (;;) {
|
|
|
|
|
+ int started = preload_fill_jobs();
|
|
|
|
|
+ int done = 0;
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < FETCH_WORKERS; i++) {
|
|
|
|
|
+ if (!fetch_workers[i].busy)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (preload_finish_worker(&fetch_workers[i]))
|
|
|
|
|
+ done++;
|
|
|
|
|
+ if (batch + done >= 4)
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ batch += (unsigned int)done;
|
|
|
|
|
+ if (batch >= 4)
|
|
|
|
|
+ return;
|
|
|
|
|
+ if (!started && !done)
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (preload_active && preload_node >= doc.nnode &&
|
|
|
|
|
+ preload_active_jobs() == 0) {
|
|
|
|
|
+ preload_active = 0;
|
|
|
|
|
+ if (preload_pending)
|
|
|
|
|
+ preload_scroll = page_scroll.offset;
|
|
|
|
|
+ else
|
|
|
|
|
+ preload_pending = 0;
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ set_status(post_status_text, post_status_error, post_status_ttl);
|
|
|
|
|
+ ngui_invalidate(&ui);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void history_push(const char *url)
|
|
static void history_push(const char *url)
|
|
@@ -2861,6 +3153,7 @@ static void load_page(const char *url, int local, int push)
|
|
|
cancel_fetch = 0;
|
|
cancel_fetch = 0;
|
|
|
preload_active = 0;
|
|
preload_active = 0;
|
|
|
preload_pending = 0;
|
|
preload_pending = 0;
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
|
|
|
js_browser_stop();
|
|
js_browser_stop();
|
|
|
js_last_status[0] = '\0';
|
|
js_last_status[0] = '\0';
|
|
@@ -7875,7 +8168,7 @@ void _start(const char *arg)
|
|
|
continue;
|
|
continue;
|
|
|
u_sleep_ms(10);
|
|
u_sleep_ms(10);
|
|
|
}
|
|
}
|
|
|
- fetch_helper_stop();
|
|
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
u_win_close();
|
|
u_win_close();
|
|
|
u_exit(0);
|
|
u_exit(0);
|
|
|
}
|
|
}
|