From 33625ae9e28a49539fc04bc0dd4e5e6b2dfb5ab6 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 3 Feb 2006 10:44:29 +0100 Subject: [PATCH] NET: Move attaching of new download to move_download This includes setting the new priority and adding the download to the list of connection downloads. If the connection has no downloads set the PRI_CANCEL priority; get_priority() requires that. --- src/network/connection.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/network/connection.c b/src/network/connection.c index e79529b7..0a90d729 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -995,14 +995,13 @@ change_connection(struct download *old, struct download *new, assertm(conn->pri[old->pri] >= 0, "priority counter underflow"); if_assert_failed conn->pri[old->pri] = 0; - conn->pri[newpri]++; del_from_list(old); old->state = S_INTERRUPTED; - if (new) { - add_to_list(conn->downloads, new); + if (list_empty(conn->downloads)) { + /* Necessary because of assertion in get_priority(). */ + conn->pri[PRI_CANCEL]++; - } else { if (conn->detached || interrupt) abort_connection(conn, S_INTERRUPTED); } @@ -1041,6 +1040,9 @@ move_download(struct download *old, struct download *new, return; } + conn->pri[new->pri]++; + add_to_list(conn->downloads, new); + change_connection(old, new, newpri, 0); }