From 47b2f4c4982fb5f063e9e83c524b2e63abaa58c4 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 17 Sep 2024 09:38:06 -0600 Subject: wip --- net9p.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 net9p.c (limited to 'net9p.c') 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 +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3-2-g168b