From 2509a796cec936e1864579d582288b89de57c137 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 10 Oct 2022 09:17:39 -0700 Subject: [PATCH] Correct async I/O setup to work for Solaris (#446) Solaris does not define O_ASYNC, but does define FASYNC and FNDELAY, which it expects to be used in place of O_ASYNC in an fcntl() to set up asynchronous I/O on a socket. This fix also generates a compiler warning if neither the O_ASYNC nor FASYNC/FNDELAY methods are available. --- src/timer.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/timer.c b/src/timer.c index 9408fe0..155e78f 100644 --- a/src/timer.c +++ b/src/timer.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -490,21 +491,29 @@ static void int_timer_init() void int_io_open(int fd) { + DBPRINT(("int_io_open %d\n", fd)); #ifdef DOS /* would turn on DOS kbd signal handler here */ -#elseif defined(O_ASYNC) - DBPRINT(("int_io_opening %d\n", fd)); +#elif defined(O_ASYNC) if (fcntl(fd, F_SETOWN, getpid()) == -1) perror("fcntl F_SETOWN error"); if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC) == -1) perror("fcntl F_SETFL on error"); +#elif defined(FASYNC) && defined(FNDELAY) + if (fcntl(fd, F_SETOWN, getpid()) == -1) perror("fcntl F_SETOWN error"); + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FNDELAY | FASYNC) == -1) perror("fcntl F_SETFL on error"); +#else +#warning "No async i/o can be enabled - investigate and remedy this" #endif } void int_io_close(int fd) { + DBPRINT(("int_io_close %d\n", fd)); #ifdef DOS /* Turn off signaller here */ -#elseif defined(O_ASYNC) +#elif defined(O_ASYNC) if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_ASYNC) == -1) perror("fcntl_F_SETFL off error"); +#elif defined(FASYNC) && defined(FNDELAY) + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~(FNDELAY | FASYNC)) == -1) perror("fcntl F_SETFL off error"); #endif }