]> granicus.if.org Git - transmission/commitdiff
(libT) don't start the web thread until we have a task to feed to curl
authorJordan Lee <jordan@transmissionbt.com>
Fri, 15 Feb 2013 01:52:47 +0000 (01:52 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Fri, 15 Feb 2013 01:52:47 +0000 (01:52 +0000)
libtransmission/session.c
libtransmission/session.h
libtransmission/web.c
libtransmission/web.h

index de072263258ba79601a19f2c1329e420535b005b..d3b50bfa2d1e70be051b920b53800c5731a6a2d8 100644 (file)
@@ -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)
index 2d402d2f4b5e16bc3f567866034301d1ca06d5ed..847df363ff6c6c3c4e53163dbdf2cdfb7254bc41 100644 (file)
@@ -110,6 +110,7 @@ struct tr_session
     bool                         isBlocklistEnabled;
     bool                         isPrefetchEnabled;
     bool                         isTorrentDoneScriptEnabled;
+    bool                         isClosing;
     bool                         isClosed;
     bool                         isIncompleteFileNamingEnabled;
     bool                         isRatioLimited;
index 69d62d824a4e76848a8ad42a55706b2acfd124a2..77dd17da165125d0d3aca8eadef51e18231bc3e5 100644 (file)
@@ -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)
index 7f4793cd75581720ed03752074ff8bfce9282651..59ad7c71a05845b5f2999f60f45f258f86dda5ea 100644 (file)
@@ -30,8 +30,6 @@ typedef enum
 }
 tr_web_task_info;
 
-void tr_webInit (tr_session * session);
-
 typedef enum
 {
     TR_WEB_CLOSE_WHEN_IDLE,