summaryrefslogtreecommitdiff
path: root/libnetio
diff options
context:
space:
mode:
Diffstat (limited to 'libnetio')
-rw-r--r--libnetio/netio_posix.c17
1 files changed, 15 insertions, 2 deletions
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 <stdlib.h> /* for shutdown(), SHUT_RD, SHUT_WR, SHUT_RDWR */
#include <string.h> /* for memset() */
#include <sys/socket.h> /* for struct sockaddr, socket(), SOCK_* flags, setsockopt(), SOL_SOCKET, SO_REUSEADDR, bind(), listen(), accept() */
+#include <unistd.h> /* for getpid() */
+
+#include <stdio.h>
#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);