Tools/NetTest - TCP stack testing, going well
[tpg/acess2.git] / Tools / NetTest / mode_cmdline.c
1 /*
2  */
3 #include <nettest.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include "cmdline.h"
8
9 // === CODE ===
10 void NetTest_Suite_Cmdline(void)
11 {
12         char line[BUFSIZ];
13         Cmdline_Backend_StartThread();
14         while( fgets(line, sizeof(line)-1, stdin) )
15         {
16                 const char *const sep = " \n\r";
17                 const char *cmd = strtok(line, sep);
18                 if(!cmd)
19                         continue;
20                 if( strcmp(cmd, "exit") == 0 ) {
21                         return ;
22                 }
23                 else if( strcmp(cmd, "tcp_echo_server") == 0 ) {
24                         const char *port_str = strtok(NULL, sep);
25                         char *end;
26                         int port = strtol(port_str, &end, 0);
27                         if(*end != '\0') {
28                                 fprintf(stderr, "ERROR: Port number '%s' not valid\n", port_str);
29                                 continue ;
30                         }
31                         
32                         Cmdline_Backend_StartEchoServer(port);
33                         // TODO: Allow stopping of the server?
34                 }
35                 else {
36                         fprintf(stderr, "ERROR: Unknown command '%s'\n", cmd);
37                 }
38         }
39         
40         // TODO: Tear down backend?
41 }

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