Просмотр исходного кода

Pass a worklist into controller_main instead of just a filename

The worklist is a vector of (modulus_file, num_iterations) pairs.
Ian Goldberg 14 лет назад
Родитель
Сommit
bc52f994e8
3 измененных файлов с 21 добавлено и 7 удалено
  1. 9 5
      controller.cc
  2. 7 1
      controller.h
  3. 5 1
      controller_main.cc

+ 9 - 5
controller.cc

@@ -747,7 +747,7 @@ static bool read_modulus(const char *filename)
     return true;
     return true;
 }
 }
 
 
-int controller_main(const char *modulus_file, unsigned short bindport)
+int controller_main(const Worklist &worklist, unsigned short bindport)
 {
 {
     // Initialize the prng with some randomness from the kernel
     // Initialize the prng with some randomness from the kernel
     unsigned char randbuf[1024];
     unsigned char randbuf[1024];
@@ -757,10 +757,14 @@ int controller_main(const char *modulus_file, unsigned short bindport)
     ZZ randzz = ZZFromBytes(randbuf, sizeof(randbuf));
     ZZ randzz = ZZFromBytes(randbuf, sizeof(randbuf));
     SetSeed(randzz);
     SetSeed(randzz);
 
 
+    if (worklist.size() == 0) {
+	return 0;
+    }
+
     // Read the modulus and the factorization of its totient from the
     // Read the modulus and the factorization of its totient from the
     // specified file
     // specified file
-    if (!read_modulus(modulus_file)) {
-	cerr << "Unable to read file " << modulus_file << "\n";
+    if (!read_modulus(worklist[0].first)) {
+	cerr << "Unable to read file " << worklist[0].first << "\n";
 	return 1;
 	return 1;
     }
     }
 
 
@@ -770,12 +774,12 @@ int controller_main(const char *modulus_file, unsigned short bindport)
     unsigned short myport;
     unsigned short myport;
 
 
     ctrlstate.listener = controller_create(evbase, bindport, &myip, &myport);
     ctrlstate.listener = controller_create(evbase, bindport, &myip, &myport);
-    struct in_addr myaddr = { myip };
 #ifdef VERBOSE
 #ifdef VERBOSE
+    struct in_addr myaddr = { myip };
     printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
     printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
 #endif
 #endif
 
 
-    ctrlstate.problems_remaining = 2;
+    ctrlstate.problems_remaining = worklist[0].second;
 
 
     // Kick off the first problem to solve
     // Kick off the first problem to solve
     generate_problem(evbase);
     generate_problem(evbase);

+ 7 - 1
controller.h

@@ -1,6 +1,12 @@
 #ifndef __CONTROLLER_H__
 #ifndef __CONTROLLER_H__
 #define __CONTROLLER_H__
 #define __CONTROLLER_H__
 
 
-int controller_main(const char *modulus_file, unsigned short bindport);
+#include <vector>
+#include <utility>
+
+typedef std::pair<const char *, unsigned int> Workentry;
+typedef std::vector<Workentry> Worklist;
+
+int controller_main(const Worklist &worklist, unsigned short bindport);
 
 
 #endif
 #endif

+ 5 - 1
controller_main.cc

@@ -49,5 +49,9 @@ int main(int argc, char **argv)
 	bindport = strtoul(argv[2], NULL, 10);
 	bindport = strtoul(argv[2], NULL, 10);
     }
     }
 
 
-    return controller_main(argv[1], bindport);
+    Worklist worklist;
+
+    worklist.push_back(Workentry(argv[1], 2));
+
+    return controller_main(worklist, bindport);
 }
 }