From 7b34cb7741c683dc623ece652032f1bf09d34140 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 29 Sep 2024 10:56:18 -0600 Subject: wip fixes --- libnetio/netio_posix.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libnetio') diff --git a/libnetio/netio_posix.c b/libnetio/netio_posix.c index 4522683..34eac80 100644 --- a/libnetio/netio_posix.c +++ b/libnetio/netio_posix.c @@ -8,6 +8,9 @@ #include /* for shutdown(), SHUT_RD, SHUT_WR, SHUT_RDWR */ #include /* for memset() */ #include /* for struct sockaddr, socket(), SOCK_* flags, setsockopt(), SOL_SOCKET, SO_REUSEADDR, bind(), listen(), accept() */ +#include /* for getpid() */ + +#include #define USE_CONFIG_NETIO_POSIX #include "config.h" @@ -113,6 +116,8 @@ int netio_listen(uint16_t port) { error(1, errno, "fcntl(F_SETFL)"); if (fcntl(sock->fd, F_SETSIG, sig_accept) < 0) error(1, errno, "fcntl(F_SETSIG)"); + if (fcntl(sock->fd, F_SETOWN, getpid()) < 0) + error(1, errno, "fcntl(F_SETOWN)"); #endif if (bind(sock->fd, &addr.gen, sizeof addr) < 0) error(1, errno, "bind"); @@ -133,9 +138,11 @@ int netio_accept(int sock) { * while waiting for us to accept(). */ for (;;) { #if CONFIG_NETIO_ISLINUX + printf("accept...\n"); cr_sema_wait(&socket_table[sock].accept_waiters); #endif int conn = accept(socket_table[sock].fd, NULL, NULL); + printf("... accept => %d\n", conn); if (conn < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { #if !CONFIG_NETIO_ISLINUX @@ -167,8 +174,11 @@ ssize_t netio_read(int conn, void *buf, size_t count) { if (aio_read(&ctl_block) < 0) return -errno; - while ((r = aio_error(&ctl_block)) == EINPROGRESS) + while ((r = aio_error(&ctl_block)) == EINPROGRESS) { + printf("read %zu...\n", count); cr_pause_and_yield(); + } + printf("...read => n=%zd errno=%d\n", aio_return(&ctl_block), r); return r ? -abs(r) : aio_return(&ctl_block); } @@ -192,8 +202,11 @@ ssize_t netio_write(int conn, void *buf, size_t goal) { if (aio_write(&ctl_block) < 0) return -errno; - while ((r = aio_error(&ctl_block)) == EINPROGRESS) + while ((r = aio_error(&ctl_block)) == EINPROGRESS) { + printf("write %zu...\n", goal-done); cr_pause_and_yield(); + } + printf("...write => n=%zd errno=%d", aio_return(&ctl_block), r); if (r < 0) return -abs(r); done += aio_return(&ctl_block); -- cgit v1.2.3-2-g168b