Tools/NetTest - TCP stack testing, going well
[tpg/acess2.git] / Tools / NetTest / mode_cmdline.c
index 5a17517..05a3933 100644 (file)
@@ -2,26 +2,40 @@
  */
 #include <nettest.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include "cmdline.h"
 
 // === CODE ===
 void NetTest_Suite_Cmdline(void)
 {
        char line[BUFSIZ];
+       Cmdline_Backend_StartThread();
        while( fgets(line, sizeof(line)-1, stdin) )
        {
-               const char *cmd = strtok(line, " ");
+               const char *const sep = " \n\r";
+               const char *cmd = strtok(line, sep);
                if(!cmd)
                        continue;
                if( strcmp(cmd, "exit") == 0 ) {
                        return ;
                }
-               else if( strcmp(cmd, "request") == 0 ) {
-                       //const char *addr = strtok(NULL, " ");
+               else if( strcmp(cmd, "tcp_echo_server") == 0 ) {
+                       const char *port_str = strtok(NULL, sep);
+                       char *end;
+                       int port = strtol(port_str, &end, 0);
+                       if(*end != '\0') {
+                               fprintf(stderr, "ERROR: Port number '%s' not valid\n", port_str);
+                               continue ;
+                       }
                        
+                       Cmdline_Backend_StartEchoServer(port);
+                       // TODO: Allow stopping of the server?
                }
                else {
                        fprintf(stderr, "ERROR: Unknown command '%s'\n", cmd);
                }
        }
+       
+       // TODO: Tear down backend?
 }

UCC git Repository :: git.ucc.asn.au