mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
NET: Replace change_connection with cancel_download and move_download
This simplifies unqueuing of downloads and makes it more obvious that the 'change' being performed is to migrate or replace an old download handle with a new one.
This commit is contained in:
parent
4a27637529
commit
3324496b57
@ -978,7 +978,7 @@ load_uri(struct uri *uri, struct uri *referrer, struct download *download,
|
||||
|
||||
|
||||
/* FIXME: one object in more connections */
|
||||
void
|
||||
static void
|
||||
change_connection(struct download *old, struct download *new,
|
||||
enum connection_priority newpri, int interrupt)
|
||||
{
|
||||
@ -1029,6 +1029,20 @@ change_connection(struct download *old, struct download *new,
|
||||
register_check_queue();
|
||||
}
|
||||
|
||||
void
|
||||
cancel_download(struct download *download, int interrupt)
|
||||
{
|
||||
change_connection(download, NULL, PRI_CANCEL, interrupt);
|
||||
}
|
||||
|
||||
void
|
||||
move_download(struct download *old, struct download *new,
|
||||
enum connection_priority newpri)
|
||||
{
|
||||
change_connection(old, new, newpri, 0);
|
||||
}
|
||||
|
||||
|
||||
/* This will remove 'pos' bytes from the start of the cache for the specified
|
||||
* connection, if the cached object is already too big. */
|
||||
void
|
||||
|
@ -89,8 +89,10 @@ void add_keepalive_connection(struct connection *conn, long timeout_in_seconds,
|
||||
void abort_connection(struct connection *, enum connection_state);
|
||||
void retry_connection(struct connection *, enum connection_state);
|
||||
|
||||
void change_connection(struct download *old, struct download *new,
|
||||
enum connection_priority newpri, int interrupt);
|
||||
void cancel_download(struct download *download, int interrupt);
|
||||
void move_download(struct download *old, struct download *new,
|
||||
enum connection_priority newpri);
|
||||
|
||||
void detach_connection(struct download *, off_t);
|
||||
void abort_all_connections(void);
|
||||
void abort_background_connections(void);
|
||||
|
@ -352,7 +352,7 @@ bittorrent_fetch_callback(struct download *download, void *data)
|
||||
|
||||
if (cached->redirect && fetcher->redirects++ < MAX_REDIRECTS) {
|
||||
if (is_in_progress_state(download->state))
|
||||
change_connection(download, NULL, PRI_CANCEL, 0);
|
||||
cancel_download(download, 0);
|
||||
|
||||
download->state = S_WAIT_REDIR;
|
||||
|
||||
@ -428,7 +428,7 @@ end_bittorrent_fetch(void *fetcher_data)
|
||||
|
||||
/* Stop any running connections. */
|
||||
if (is_in_progress_state(fetcher->download.state))
|
||||
change_connection(&fetcher->download, NULL, PRI_CANCEL, 0);
|
||||
cancel_download(&fetcher->download, 0);
|
||||
|
||||
mem_free(fetcher);
|
||||
}
|
||||
|
@ -141,8 +141,7 @@ abort_download(struct file_download *file_download)
|
||||
if (file_download->dlg_data)
|
||||
cancel_dialog(file_download->dlg_data, NULL);
|
||||
if (is_in_progress_state(file_download->download.state))
|
||||
change_connection(&file_download->download, NULL, PRI_CANCEL,
|
||||
file_download->stop);
|
||||
cancel_download(&file_download->download, file_download->stop);
|
||||
if (file_download->uri) done_uri(file_download->uri);
|
||||
|
||||
if (file_download->handle != -1) {
|
||||
@ -391,7 +390,7 @@ download_data(struct download *download, struct file_download *file_download)
|
||||
|
||||
if (cached->redirect && file_download->redirect_cnt++ < MAX_REDIRECTS) {
|
||||
if (is_in_progress_state(download->state))
|
||||
change_connection(&file_download->download, NULL, PRI_CANCEL, 0);
|
||||
cancel_download(&file_download->download, 0);
|
||||
|
||||
assertm(compare_uri(cached->uri, file_download->uri, 0),
|
||||
"Redirecting using bad base URI");
|
||||
@ -822,7 +821,7 @@ continue_download_do(struct terminal *term, int fd, void *data, int resume)
|
||||
* handler can become initialized. */
|
||||
display_download(term, file_download, type_query->ses);
|
||||
|
||||
change_connection(&type_query->download, &file_download->download, PRI_DOWNLOAD, 0);
|
||||
move_download(&type_query->download, &file_download->download, PRI_DOWNLOAD);
|
||||
done_type_query(type_query);
|
||||
|
||||
mem_free(codw_hop);
|
||||
@ -888,7 +887,7 @@ init_type_query(struct session *ses, struct download *download,
|
||||
type_query->cached = cached;
|
||||
object_lock(type_query->cached);
|
||||
|
||||
change_connection(download, &type_query->download, PRI_MAIN, 0);
|
||||
move_download(download, &type_query->download, PRI_MAIN);
|
||||
download->state = S_OK;
|
||||
|
||||
add_to_list(ses->type_queries, type_query);
|
||||
@ -901,7 +900,7 @@ done_type_query(struct type_query *type_query)
|
||||
{
|
||||
/* Unregister any active download */
|
||||
if (is_in_progress_state(type_query->download.state))
|
||||
change_connection(&type_query->download, NULL, PRI_CANCEL, 0);
|
||||
cancel_download(&type_query->download, 0);
|
||||
|
||||
object_unlock(type_query->cached);
|
||||
done_uri(type_query->uri);
|
||||
@ -916,8 +915,9 @@ void
|
||||
tp_cancel(void *data)
|
||||
{
|
||||
struct type_query *type_query = data;
|
||||
|
||||
/* XXX: Should we really abort? (1 vs 0 as the last param) --pasky */
|
||||
change_connection(&type_query->download, NULL, PRI_CANCEL, 1);
|
||||
cancel_download(&type_query->download, 1);
|
||||
done_type_query(type_query);
|
||||
}
|
||||
|
||||
@ -968,7 +968,7 @@ tp_display(struct type_query *type_query)
|
||||
new->data = ses;
|
||||
|
||||
if (is_in_progress_state(old->state))
|
||||
change_connection(old, new, PRI_MAIN, 0);
|
||||
move_download(old, new, PRI_MAIN);
|
||||
else
|
||||
new->state = old->state;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ abort_files_load(struct session *ses, int interrupt)
|
||||
continue;
|
||||
|
||||
more = 1;
|
||||
change_connection(&ftl->download, NULL, PRI_CANCEL, interrupt);
|
||||
cancel_download(&ftl->download, interrupt);
|
||||
}
|
||||
|
||||
if (!more) break;
|
||||
@ -663,7 +663,7 @@ request_additional_file(struct session *ses, unsigned char *name, struct uri *ur
|
||||
if (compare_uri(ftl->uri, uri, URI_BASE)) {
|
||||
if (ftl->pri > pri) {
|
||||
ftl->pri = pri;
|
||||
change_connection(&ftl->download, &ftl->download, pri, 0);
|
||||
move_download(&ftl->download, &ftl->download, pri);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -1116,7 +1116,7 @@ abort_loading(struct session *ses, int interrupt)
|
||||
struct location *loc = cur_loc(ses);
|
||||
|
||||
if (is_in_progress_state(loc->download.state))
|
||||
change_connection(&loc->download, NULL, PRI_CANCEL, interrupt);
|
||||
cancel_download(&loc->download, interrupt);
|
||||
abort_files_load(ses, interrupt);
|
||||
}
|
||||
abort_preloading(ses, interrupt);
|
||||
|
@ -55,7 +55,7 @@ abort_preloading(struct session *ses, int interrupt)
|
||||
{
|
||||
if (!ses->task.type) return;
|
||||
|
||||
change_connection(&ses->loading, NULL, PRI_CANCEL, interrupt);
|
||||
cancel_download(&ses->loading, interrupt);
|
||||
free_task(ses);
|
||||
}
|
||||
|
||||
@ -506,7 +506,7 @@ do_move(struct session *ses, struct download **download_p)
|
||||
if (is_in_progress_state((*download_p)->state)) {
|
||||
if (have_location(ses))
|
||||
*download_p = &cur_loc(ses)->download;
|
||||
change_connection(&ses->loading, *download_p, PRI_MAIN, 0);
|
||||
move_download(&ses->loading, *download_p, PRI_MAIN);
|
||||
} else if (have_location(ses)) {
|
||||
cur_loc(ses)->download.state = ses->loading.state;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ dump_loading_callback(struct download *download, void *p)
|
||||
struct uri *uri = cached->redirect;
|
||||
|
||||
if (is_in_progress_state(download->state))
|
||||
change_connection(download, NULL, PRI_CANCEL, 0);
|
||||
cancel_download(download, 0);
|
||||
|
||||
load_uri(uri, cached->uri, download, PRI_MAIN, 0, -1);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user