From: John Hodge Date: Thu, 15 Apr 2010 02:42:33 +0000 (+0800) Subject: Added test server to git tree X-Git-Tag: rel0.06~236 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=05ebedc80e5aab98be31a032eed5caf28944ea57;p=tpg%2Facess2.git Added test server to git tree - Test server opens a server on port 80 and serves a hello world page --- diff --git a/Usermode/Applications/testserver_src/Makefile b/Usermode/Applications/testserver_src/Makefile new file mode 100644 index 00000000..5b6d2554 --- /dev/null +++ b/Usermode/Applications/testserver_src/Makefile @@ -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 index 00000000..3274174a --- /dev/null +++ b/Usermode/Applications/testserver_src/main.c @@ -0,0 +1,63 @@ +/* + * Acess2 Test Server + */ +#include +#include +#include + +/** + * \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; +}