From bda58a124af2293a462734acdc88e1a655966dfe Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 4 Oct 2008 13:00:57 +0300 Subject: [PATCH] Revert "Use given connections id in connection_disappeared()." This reverts src/{network,sched}/connection.c CVS revision 1.43, which was made on 2003-07-03 and converted to Git commit cae65f7941628109b51ffb2e2d05882fbbdc73ef in elinks-history. It is pointless to check whether (c == d && c->id == d->id). If c == d, then surely c->id == d->id, and I wouldn't be surprised to see a compiler optimize that out. Whereas, by taking the id as a parameter, connection_disappeared() can check whether the pointer now points to a new struct connection with a different id. --- src/network/connection.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/network/connection.c b/src/network/connection.c index 2f4271bd0..61614ee80 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -118,13 +118,19 @@ get_connections_transfering_count(void) return i; } +/** Check whether the pointer @a conn still points to a connection + * with the given @a id. If the struct connection has already been + * freed, this returns 0. By comparing connection.id, this function + * can usually detect even the case where a different connection has + * been created at the same address. For that to work, the caller + * must save the connection.id before the connection can be deleted. */ static inline int -connection_disappeared(struct connection *conn) +connection_disappeared(struct connection *conn, unsigned int id) { struct connection *c; foreach (c, connection_queue) - if (conn == c && conn->id == c->id) + if (conn == c && id == c->id) return 0; return 1; @@ -349,9 +355,11 @@ set_connection_state(struct connection *conn, struct connection_state state) conn->state = state; if (is_in_state(conn->state, S_TRANS)) { if (progress->timer == TIMER_ID_UNDEF) { + const unsigned int id = conn->id; + start_update_progress(progress, (void (*)(void *)) stat_timer, conn); update_connection_progress(conn); - if (connection_disappeared(conn)) + if (connection_disappeared(conn, id)) return; } @@ -420,13 +428,15 @@ void notify_connection_callbacks(struct connection *conn) { struct connection_state state = conn->state; + unsigned int id = conn->id; struct download *download, *next; foreachsafe (download, next, conn->downloads) { download->cached = conn->cached; if (download->callback) download->callback(download, download->data); - if (is_in_progress_state(state) && connection_disappeared(conn)) + if (is_in_progress_state(state) + && connection_disappeared(conn, id)) return; } }