From: Jordan Lee Date: Fri, 15 Feb 2013 01:52:47 +0000 (+0000) Subject: (libT) don't start the web thread until we have a task to feed to curl X-Git-Tag: 2.80~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fcdec9a8bc743b3074e11bdfe133c6b0cbfe00c9;p=transmission (libT) don't start the web thread until we have a task to feed to curl --- diff --git a/libtransmission/session.c b/libtransmission/session.c index de0722632..d3b50bfa2 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -728,10 +728,6 @@ tr_sessionInitImpl (void * vdata) tr_statsInit (session); - tr_webInit (session); - while (session->web == NULL) - tr_wait_msec (50); - tr_sessionSet (session, &settings); tr_udpInit (session); @@ -1756,6 +1752,8 @@ sessionCloseImpl (void * vsession) assert (tr_isSession (session)); + session->isClosing = true; + free_incoming_peer_port (session); if (session->isLPDEnabled) diff --git a/libtransmission/session.h b/libtransmission/session.h index 2d402d2f4..847df363f 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -110,6 +110,7 @@ struct tr_session bool isBlocklistEnabled; bool isPrefetchEnabled; bool isTorrentDoneScriptEnabled; + bool isClosing; bool isClosed; bool isIncompleteFileNamingEnabled; bool isRatioLimited; diff --git a/libtransmission/web.c b/libtransmission/web.c index 69d62d824..77dd17da1 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -247,6 +247,8 @@ tr_webRun (tr_session * session, NULL); } +static void tr_webThreadFunc (void * vsession); + struct tr_web_task * tr_webRunWithBuffer (tr_session * session, const char * url, @@ -256,12 +258,20 @@ tr_webRunWithBuffer (tr_session * session, void * done_func_user_data, struct evbuffer * buffer) { - struct tr_web * web = session->web; + struct tr_web_task * task = NULL; - if (web != NULL) + if (!session->isClosing) { - struct tr_web_task * task = tr_new0 (struct tr_web_task, 1); + if (session->web == NULL) + { + tr_threadNew (tr_webThreadFunc, session); + while (session->web == NULL) + tr_wait_msec (20); + } + + task = tr_new0 (struct tr_web_task, 1); + task = tr_new0 (struct tr_web_task, 1); task->session = session; task->url = tr_strdup (url); task->range = tr_strdup (range); @@ -271,14 +281,13 @@ tr_webRunWithBuffer (tr_session * session, task->response = buffer ? buffer : evbuffer_new (); task->freebuf = buffer ? NULL : task->response; - tr_lockLock (web->taskLock); - task->next = web->tasks; - web->tasks = task; - tr_lockUnlock (web->taskLock); - return task; + tr_lockLock (session->web->taskLock); + task->next = session->web->tasks; + session->web->tasks = task; + tr_lockUnlock (session->web->taskLock); } - return NULL; + return task; } /** @@ -450,11 +459,6 @@ tr_webThreadFunc (void * vsession) session->web = NULL; } -void -tr_webInit (tr_session * session) -{ - tr_threadNew (tr_webThreadFunc, session); -} void tr_webClose (tr_session * session, tr_web_close_mode close_mode) diff --git a/libtransmission/web.h b/libtransmission/web.h index 7f4793cd7..59ad7c71a 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -30,8 +30,6 @@ typedef enum } tr_web_task_info; -void tr_webInit (tr_session * session); - typedef enum { TR_WEB_CLOSE_WHEN_IDLE,