summaryrefslogtreecommitdiff
path: root/net9p.c
diff options
context:
space:
mode:
Diffstat (limited to 'net9p.c')
-rw-r--r--net9p.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/net9p.c b/net9p.c
new file mode 100644
index 0000000..99d3d72
--- /dev/null
+++ b/net9p.c
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "net9p.h"
+#include "coroutine.h"
+
+void net9p_listen_cr(void *_stack) {
+ static union {
+ struct sockaddr_in in;
+ struct sockaddr gen;
+ } addr = {0};
+ if (!addr.in.sin_family) {
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = 0x2823;
+ }
+ net9p_listen_stack_t *stack = _stack;
+
+ cr_begin();
+
+ stack->fd = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0);
+ bind(stack->fd, &addr.gen, sizeof addr);
+ listen(stack->fd, 5);
+
+ for (;;) {
+ int conn = accept(stack->fd, NULL, NULL);
+ if (conn >= 0) {
+ net9p_worker_stack_t *connstack = malloc(sizeof(net9p_worker_stack_t));
+ connstack->fd = conn;
+ coroutine_add(net9p_worker_cr, connstack);
+ }
+ cr_yield();
+ }
+
+ cr_end();
+}
+
+void net9p_worker_cr(void *_stack) {
+ net9p_worker_stack_t *stack = _stack;
+}