[pan2: 103/268] adding upload limits



commit d6dffc89662bfaf6776ac7b0ec0630c91ae99c5d
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Sun Jul 3 10:22:30 2011 +0200

    adding upload limits

 pan/tasks/queue.cc       |   32 +++++++++++++++++++++++++++++++-
 pan/tasks/queue.h        |    4 ++++
 pan/tasks/task-upload.cc |    3 ++-
 pan/tasks/task-upload.h  |    1 +
 pan/tasks/task.h         |    7 ++++++-
 5 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index f24dc19..698c0d1 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -48,7 +48,8 @@ Queue :: Queue (ServerInfo         & server_info,
   _save_delay_secs (save_delay_secs),
   _needs_saving (false),
   _last_time_saved (0),
-  _archive (archive)
+  _archive (archive),
+  _current_uploads(0)
 {
   tasks_t tasks;
   _archive.load_tasks (tasks);
@@ -117,7 +118,12 @@ Queue :: clean_n_save ()
     Task * task  (*it);
     const Task::State& state (task->get_state());
     if (state._work==Task::COMPLETED || _removing.count(task))
+    {
+      TaskUpload* t = dynamic_cast<TaskUpload*>(task);
+      if (task)
+        --_current_uploads;
       remove_task (task);
+    }
   }
 
   // maybe save the task list.
@@ -251,6 +257,9 @@ Queue :: process_task (Task * task)
   if (state._work == Task::COMPLETED)
   {
     debug ("completed");
+    TaskUpload* t = dynamic_cast<TaskUpload*>(task);
+    if (task)
+      --_current_uploads;
     remove_task (task);
   }
   else if (_removing.count(task))
@@ -273,6 +282,14 @@ Queue :: process_task (Task * task)
     debug ("working");
     // do nothing
   }
+  else if (state._work == Task::PAUSED)
+  {
+    std::cerr<<"paused task\n";
+    debug ("paused");
+    const Task::State::unique_servers_t& servers (state._servers);
+    foreach_const (Task::State::unique_servers_t, servers, it)
+      request_wakeup ((TaskUpload*)task,*it);
+  }
   else if (state._work == Task::NEED_DECODER)
   {
     if (!_decoder_task)
@@ -351,6 +368,19 @@ Queue :: find_first_task_needing_server (const Quark& server)
   return 0;
 }
 
+void
+Queue :: request_wakeup (TaskUpload* task, const Quark& server)
+{
+  int max (_server_info.get_server_limits(server));
+  std::cerr<<"request wakeup "<<_current_uploads<<" "<<max<<std::endl;
+  if (_current_uploads < max)
+  {
+    std::cerr<<"task wakeup ("<<max<<"(!\n";
+    ++_current_uploads;
+    task->wakeup();
+  }
+}
+
 bool
 Queue :: find_best_server (const Task::State::unique_servers_t& servers, Quark& setme)
 {
diff --git a/pan/tasks/queue.h b/pan/tasks/queue.h
index a573a2c..e1bd4ae 100644
--- a/pan/tasks/queue.h
+++ b/pan/tasks/queue.h
@@ -189,6 +189,9 @@ namespace pan
       Task* find_first_task_needing_server (const Quark& server);
       Task* find_first_task_needing_decoder ();
       Task* find_first_task_needing_encoder ();
+
+      void request_wakeup (TaskUpload* task, const Quark& server);
+
       bool find_best_server (const Task::State::unique_servers_t& servers, Quark& setme);
       bool task_is_active (const Task*) const;
 
@@ -232,6 +235,7 @@ namespace pan
       bool _needs_saving;
       time_t _last_time_saved;
       quarks_t _mids;
+      int _current_uploads;
 
     private:
       TaskArchive& _archive;
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index ee7e254..2beafd9 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -98,7 +98,8 @@ TaskUpload :: TaskUpload (const std::string         & filename,
   struct stat sb;
   stat(filename.c_str(),&sb);
   _bytes = sb.st_size;
-  update_work ();
+//  update_work ();
+  _state.set_paused();
 }
 
 void
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index 78f4da8..5530a84 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -178,6 +178,7 @@ namespace pan
     public:
       void build_needed_tasks();
       std::set<int> _wanted;
+      void wakeup() { update_work(); }
 
     private:
       GMimeMessage * _msg;
diff --git a/pan/tasks/task.h b/pan/tasks/task.h
index b1138d6..7082262 100644
--- a/pan/tasks/task.h
+++ b/pan/tasks/task.h
@@ -57,7 +57,9 @@ namespace pan
             NEED_DECODER,
             NEED_ENCODER,
             /** Task is running */
-            WORKING
+            WORKING,
+
+            PAUSED
          };
 
          /**
@@ -82,6 +84,9 @@ namespace pan
                void set_completed () {
                    _work = COMPLETED; _servers.clear(); }
 
+               void set_paused () {
+                   _work = PAUSED; _servers.clear(); }
+
                void set_working () {
                   _work = WORKING; _servers.clear(); }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]