Usermode/libc - Fix strchr and strrchr behavior
[tpg/acess2.git] / Tools / NetTest / cmdline_backend.c
1 /*
2  * Acess2 Network Tester
3  * - By John Hodge (thePowersGang)
4  *
5  * cmdline_backend.c
6  * - Backend Thread for 'cmdline' suite
7  */
8 #define DEBUG   0
9 #include "cmdline.h"
10 #include "tcpserver.h"
11 #include <vfs_ext.h>
12 #include <threads.h>
13 #include <events.h>
14
15 // === PROTOTYES ===
16 void    Cmdline_Backend_Thread(void *unused);
17
18 // === GLOBALS ===
19 tThread *gpCmdline_WorkerThread;
20 tNetTest_TCPServer      *gpCmdline_TCPEchoServer;
21
22 // === CODE ===
23 void Cmdline_Backend_StartThread(void)
24 {
25         ASSERT(!gpCmdline_WorkerThread);
26         gpCmdline_WorkerThread = Proc_SpawnWorker(Cmdline_Backend_Thread, NULL);
27 }
28
29 void Cmdline_Backend_Thread(void *unused)
30 {
31         Threads_SetName("Cmdline Worker");
32         for( ;; )
33         {
34                 fd_set  rfd, wfd, efd;
35                  int    max = -1;
36                 
37                 FD_ZERO(&rfd);
38                 FD_ZERO(&wfd);
39                 
40                 LOG("gpCmdline_TCPEchoServer = %p", gpCmdline_TCPEchoServer);
41                 if(gpCmdline_TCPEchoServer)
42                         max = MAX(max, NetTest_TCPServer_FillSelect(gpCmdline_TCPEchoServer, &rfd));
43                 
44                 //memcpy(&wfd, &rfd, sizeof(rfd));
45                 memcpy(&efd, &rfd, sizeof(rfd));
46                 
47                 LOG("max = %i", max);
48                 int rv = VFS_Select(max+1, &rfd, &wfd, &efd, NULL, THREAD_EVENT_USER1, false);
49                 LOG("rv = %i", rv);
50                 
51                 if( rv < 0 ) {
52                         // Oh, shite
53                 }
54                 
55                 // Woken with no file changes, skip checking
56                 if( rv == 0 )
57                         continue ;
58                 
59                 if(gpCmdline_TCPEchoServer)
60                         NetTest_TCPServer_HandleSelect(gpCmdline_TCPEchoServer, &rfd, &wfd, &efd);
61         }
62 }
63
64 void Cmdline_Backend_StartEchoServer(int Port)
65 {
66         if(gpCmdline_TCPEchoServer)
67         {
68                 // Oops, two
69         }
70         else
71         {
72                 gpCmdline_TCPEchoServer = NetTest_TCPServer_Create(Port);
73                 Log_Debug("Cmdline", "Echo Server = %p", gpCmdline_TCPEchoServer);
74                 Threads_PostEvent(gpCmdline_WorkerThread, THREAD_EVENT_USER1);
75         }
76 }

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