#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; }