aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2020-11-19 18:53:48 +0100
committerMarvin Borner2020-11-19 18:53:48 +0100
commitd8036aa78139c7890d8adde6ee937929623dbffb (patch)
tree306420b0c89769052cd31297de489884584797f1 /apps
parenteafd1550ec8fe8887674e9be79f9704bf3a39a8a (diff)
Reimplemented basic webserver
Diffstat (limited to 'apps')
-rw-r--r--apps/Makefile2
-rw-r--r--apps/server.c28
2 files changed, 29 insertions, 1 deletions
diff --git a/apps/Makefile b/apps/Makefile
index ea212d9..8f0e150 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -1,6 +1,6 @@
# MIT License, Copyright (c) 2020 Marvin Borner
-COBJS = init.o wm.o mandelbrot.o window.o exec.o files.o test.o cc.o browser.o
+COBJS = init.o wm.o mandelbrot.o window.o exec.o files.o test.o cc.o browser.o server.o
CC = ccache ../cross/opt/bin/i686-elf-gcc
LD = ccache ../cross/opt/bin/i686-elf-ld
OC = ccache ../cross/opt/bin/i686-elf-objcopy
diff --git a/apps/server.c b/apps/server.c
new file mode 100644
index 0000000..646e876
--- /dev/null
+++ b/apps/server.c
@@ -0,0 +1,28 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <assert.h>
+#include <net.h>
+#include <print.h>
+#include <str.h>
+
+#define PORT 8000
+#define RESP "HTTP/1.1 200\r\nContent-Length: 14\r\nConnection: close\r\n\r\n<h1>Hallo</h1>"
+
+int main()
+{
+ printf("Server running on port %d\n", PORT);
+
+ while (1) {
+ struct socket *socket = net_open(S_TCP);
+ assert(socket);
+ socket->src_port = PORT;
+ socket->state = S_CONNECTED;
+ char buf[4096] = { 0 };
+ net_receive(socket, buf, 4096);
+ printf("%s\n", buf);
+ net_send(socket, strdup(RESP), strlen(RESP));
+ /* net_close(socket); // TODO: Fix */
+ }
+
+ return 0;
+}