From 7d30ad3ff6a71c721a48d9188ea5b429fd6dd4d7 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 31 Dec 2015 14:24:15 +0000 Subject: [PATCH] #5891: Move UDP shutdown timer setup to sessionCloseImplStart --- libtransmission/session.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/libtransmission/session.c b/libtransmission/session.c index 146c0fd02..0643d979b 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -1780,6 +1780,11 @@ compareTorrentByCur (const void * va, const void * vb) static void closeBlocklists (tr_session *); +static void +sessionCloseImplWaitForIdleUdp (evutil_socket_t foo UNUSED, + short bar UNUSED, + void * vsession); + static void sessionCloseImplStart (tr_session * session) { @@ -1826,26 +1831,15 @@ sessionCloseImplStart (tr_session * session) tr_cacheFree (session->cache); session->cache = NULL; + + /* saveTimer is not used at this point, reusing for UDP shutdown wait */ + assert (session->saveTimer == NULL); + session->saveTimer = evtimer_new (session->event_base, sessionCloseImplWaitForIdleUdp, session); + tr_timerAdd (session->saveTimer, 0, 0); } static void -sessionCloseImplFinish (tr_session * session) -{ - /* we had to wait until UDP trackers were closed before closing these: */ - evdns_base_free (session->evdns_base, 0); - session->evdns_base = NULL; - tr_tracker_udp_close (session); - tr_udpUninit (session); - - tr_statsClose (session); - tr_peerMgrFree (session->peerMgr); - - closeBlocklists (session); - - tr_fdClose (session); - - session->isClosed = true; -} +sessionCloseImplFinish (tr_session * session); static void sessionCloseImplWaitForIdleUdp (evutil_socket_t foo UNUSED, @@ -1868,6 +1862,25 @@ sessionCloseImplWaitForIdleUdp (evutil_socket_t foo UNUSED, sessionCloseImplFinish (session); } +static void +sessionCloseImplFinish (tr_session * session) +{ + /* we had to wait until UDP trackers were closed before closing these: */ + evdns_base_free (session->evdns_base, 0); + session->evdns_base = NULL; + tr_tracker_udp_close (session); + tr_udpUninit (session); + + tr_statsClose (session); + tr_peerMgrFree (session->peerMgr); + + closeBlocklists (session); + + tr_fdClose (session); + + session->isClosed = true; +} + static void sessionCloseImpl (void * vsession) { @@ -1876,11 +1889,6 @@ sessionCloseImpl (void * vsession) assert (tr_isSession (session)); sessionCloseImplStart (session); - - /* saveTimer is not used at this point, reusing for UDP shutdown wait */ - assert (session->saveTimer == NULL); - session->saveTimer = evtimer_new (session->event_base, sessionCloseImplWaitForIdleUdp, session); - tr_timerAdd (session->saveTimer, 0, 0); } static int