Added test server to git tree
authorJohn Hodge <[email protected]>
Thu, 15 Apr 2010 02:42:33 +0000 (10:42 +0800)
committerJohn Hodge <[email protected]>
Thu, 15 Apr 2010 02:42:33 +0000 (10:42 +0800)
- Test server opens a server on port 80 and serves a hello world page

Usermode/Applications/testserver_src/Makefile [new file with mode: 0644]
Usermode/Applications/testserver_src/main.c [new file with mode: 0644]

diff --git a/Usermode/Applications/testserver_src/Makefile b/Usermode/Applications/testserver_src/Makefile
new file mode 100644 (file)
index 0000000..5b6d255
--- /dev/null
@@ -0,0 +1,9 @@
+# Project: testsrv
+
+-include ../Makefile.cfg
+
+OBJ = main.o
+BIN = ../testsrv
+
+-include ../Makefile.tpl
+
diff --git a/Usermode/Applications/testserver_src/main.c b/Usermode/Applications/testserver_src/main.c
new file mode 100644 (file)
index 0000000..3274174
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Acess2 Test Server
+ */
+#include <acess/sys.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/**
+ * \fn int main(int argc, char *argv[])
+ * \brief Entrypoint
+ */
+int main(int argc, char *argv[])
+{
+        int    srv = -1;
+        int    con = -1;
+        int    len;
+       uint16_t        port;
+       char    buf[8+1];
+       uint8_t data[4096];     // Packet Data
+        
+       srv = open("/Devices/ip/1/tcps", OPENFLAG_READ|OPENFLAG_EXEC);
+       if(srv == -1) {
+               fprintf(stderr, "Unable top open TCP server '/Devices/ip/1/tcps'\n");
+               return -1;
+       }
+       port = 80;      ioctl(srv, 4, &port);   // Set Port
+       
+       for(;;)
+       {
+               readdir( srv, buf );
+               printf("Connection '/Devices/ip/1/tcps/%s'\n", buf);
+               con = _SysOpenChild(srv, buf, OPENFLAG_READ|OPENFLAG_WRITE);
+               if(con == -1) {
+                       fprintf(stderr, "Wtf! Why didn't this open?\n");
+                       return 1;
+               }
+               
+               len = read(con, 4096, data);
+               if( len == -1 ) {
+                       printf("Connection closed\n");
+                       close(con);
+                       continue;
+               }
+               if( len != 0 )
+               {
+                       printf("Packet Data: (%i bytes)\n", len);
+                       printf("%s\n", data);
+                       printf("--- EOP ---\n");
+               }
+               
+               #define RET_STR "HTTP/1.1 200 OK\r\n"\
+                       "Content-Type: text/plain\r\n"\
+                       "Content-Length: 6\r\n"\
+                       "\r\n"\
+                       "Hello!"
+               
+               write(con, sizeof(RET_STR), RET_STR);
+               
+               close(con);
+       }
+       
+       return 0;
+}

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