]> git.seodisparate.com - UDPConnection/commitdiff
Add command parsing for NetworkTest
authorStephen Seo <seo.disparate@gmail.com>
Mon, 16 Sep 2019 02:52:03 +0000 (11:52 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 16 Sep 2019 02:52:03 +0000 (11:52 +0900)
cpp_impl/src/test/UDPC_NetworkTest.cpp

index b2f997621bea95c08664e45bcbdc81f3c264a051..04b2f6f20daf45eef18f8586c43c11e3dca9eec0 100644 (file)
@@ -1,2 +1,54 @@
-int main() {
+#include <cstring>
+#include <string>
+#include <cstdio>
+
+#include <UDPConnection.h>
+
+void usage() {
+    puts("[-c | -s] - client or server (default server)");
+    puts("-ll <addr> - listen addr");
+    puts("-lp <port> - listen port");
+    puts("-cl <addr> - connection addr (client only)");
+    puts("-cp <port> - connection port (client only)");
+}
+
+int main(int argc, char **argv) {
+    --argc; ++argv;
+    if(argc == 0) {
+        usage();
+        return 0;
+    }
+
+    bool isClient = false;
+    const char *listenAddr = nullptr;
+    const char *listenPort = nullptr;
+    const char *connectionAddr = nullptr;
+    const char *connectionPort = nullptr;
+    while(argc > 0) {
+        if(std::strcmp(argv[0], "-c") == 0) {
+            isClient = true;
+        } else if(std::strcmp(argv[0], "-s") == 0) {
+            isClient = false;
+        } else if(std::strcmp(argv[0], "-ll") == 0 && argc > 1) {
+            --argc; ++argv;
+            listenAddr = argv[0];
+        } else if(std::strcmp(argv[0], "-lp") == 0 && argc > 1) {
+            --argc; ++argv;
+            listenPort = argv[0];
+        } else if(std::strcmp(argv[0], "-cl") == 0 && argc > 1) {
+            --argc; ++argv;
+            connectionAddr = argv[0];
+        } else if(std::strcmp(argv[0], "-cp") == 0 && argc > 1) {
+            --argc; ++argv;
+            connectionPort = argv[0];
+        } else {
+            printf("ERROR: invalid argument \"%s\"\n", argv[0]);
+            usage();
+            return 1;
+        }
+
+        --argc; ++argv;
+    }
+
+    return 0;
 }