Explorar el Código

Add a callback to controller_main to report the bound address and port

Ian Goldberg hace 14 años
padre
commit
639ddc0fe3
Se han modificado 3 ficheros con 14 adiciones y 6 borrados
  1. 6 3
      controller.cc
  2. 2 1
      controller.h
  3. 6 2
      controller_main.cc

+ 6 - 3
controller.cc

@@ -757,7 +757,8 @@ static struct evconnlistener *controller_create(struct event_base *evbase,
 	ip, boundport, false);
 }
 
-int controller_main(const Worklist &worklist, unsigned short bindport)
+int controller_main(const Worklist &worklist, unsigned short bindport,
+    void (*boundcb)(const char *boundaddr, unsigned short boundport))
 {
     // Initialize the prng with some randomness from the kernel
     unsigned char randbuf[1024];
@@ -786,8 +787,10 @@ int controller_main(const Worklist &worklist, unsigned short bindport)
     unsigned short myport;
 
     ctrlstate.listener = controller_create(evbase, bindport, &myip, &myport);
-    struct in_addr myaddr = { myip };
-    printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
+    if (ctrlstate.listener && boundcb) {
+	struct in_addr myaddr = { myip };
+	boundcb(inet_ntoa(myaddr), ntohs(myport));
+    }
 
     // Kick off the first problem to solve
     generate_problem(evbase);

+ 2 - 1
controller.h

@@ -7,6 +7,7 @@
 typedef std::pair<const char *, unsigned int> Workentry;
 typedef std::vector<Workentry> Worklist;
 
-int controller_main(const Worklist &worklist, unsigned short bindport);
+int controller_main(const Worklist &worklist, unsigned short bindport,
+    void (*boundcb)(const char *boundaddr, unsigned short boundport));
 
 #endif

+ 6 - 2
controller_main.cc

@@ -37,6 +37,11 @@ void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
     }
 }
 
+static void boundcb(const char *boundaddr, unsigned short boundport)
+{
+    cout << "Listening on " << boundaddr << ":" << boundport << "\n";
+}
+
 int main(int argc, char **argv)
 {
     unsigned short bindport = 0;
@@ -53,12 +58,11 @@ int main(int argc, char **argv)
 	return 1;
     }
 
-
     Worklist worklist;
 
     for (int i=1;i<argc;i+=2) {
 	worklist.push_back(Workentry(argv[i], strtoul(argv[i+1], NULL, 10)));
     }
 
-    return controller_main(worklist, bindport);
+    return controller_main(worklist, bindport, boundcb);
 }