]> PatchyGit - patchyircd.git/commitdiff
netpoll: automatically choose implementation
authorEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 08:04:15 +0000 (10:04 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 08:04:15 +0000 (10:04 +0200)
config.example.mk
src/job.cpp
src/netpoll.cpp

index c877fc0..0ecbd90 100644 (file)
@@ -2,7 +2,7 @@ HEADERS+=config.mk
 CXX=clang++
 WARNS=-Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
 #-Wmissing-variable-declarations
-CXXFLAGS=$(WARNS) -std=c++20 -DNETPOLL_USE_LIBUV -D_GNU_SOURCE
+CXXFLAGS=$(WARNS) -std=c++20 -D_GNU_SOURCE
 USE_UV=1
 USE_TLS=1
 USE_LUA=1
index 248164b..91e34a6 100644 (file)
@@ -18,7 +18,7 @@ static int joblen = 0, jobcap = 0;
 static pid_t current_child = -1;
 static int current_result = 0;
 
-#ifdef NETPOLL_USE_LIBUV
+#ifdef HAS_UV
 #include <uv.h>
 static uv_signal_t uvsigchld, uvsigint;
 #define HANDLE_ARG [[maybe_unused]] uv_signal_t *handle,
@@ -55,7 +55,7 @@ void job_init(void)
        if (sigaction(SIGPIPE, &sa, NULL) == -1)
                perror("sigaction");
 
-#ifndef NETPOLL_USE_LIBUV
+#ifndef HAS_UV
        sa.sa_handler = job_child;
        sa.sa_flags = SA_RESTART;
        if (sigaction(SIGCHLD, &sa, NULL) == -1)
@@ -75,7 +75,7 @@ void job_init(void)
 }
 void job_fini(void)
 {
-#ifdef NETPOLL_USE_LIBUV
+#ifdef HAS_UV
        uv_close((uv_handle_t *)&uvsigchld, 0);
        uv_close((uv_handle_t *)&uvsigint, 0);
 #endif
@@ -107,7 +107,7 @@ static void job_process(void)
 }
 void job_process_begin(void)
 {
-#ifndef NETPOLL_USE_LIBUV
+#ifndef HAS_UV
        sigset_t mask;
        sigemptyset(&mask);
        sigaddset(&mask, SIGCHLD);
@@ -118,7 +118,7 @@ void job_process_begin(void)
 void job_process_end(void)
 {
        job_process();
-#ifndef NETPOLL_USE_LIBUV
+#ifndef HAS_UV
        sigset_t mask;
        sigemptyset(&mask);
        sigaddset(&mask, SIGCHLD);
index 870256d..017bcc1 100644 (file)
@@ -5,7 +5,7 @@ namespace netpoll {
 static struct net_pollfd fds[NETPOLL_MAXFDS] = {};
 static int nfds = 0;
 
-#if defined(NETPOLL_USE_POLL)
+#ifndef HAS_UV
 static struct pollfd pollfds[NETPOLL_MAXFDS] = {};
 static int lastptr = 0;
 void init(void)
@@ -62,7 +62,7 @@ int get(struct net_pollfd *out)
        *out = fds[lastptr-1];
        return ev;
 }
-#elif defined(NETPOLL_USE_LIBUV)
+#else
 #include <uv.h>
 #define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
 struct polldata {
@@ -177,8 +177,6 @@ int get(struct net_pollfd *out)
        *out = fds[lastptr-1];
        return ev;
 }
-#else
-#error pick a netpoll implementation
 #endif
 
 static int search(SOCKET fd) {
@@ -231,7 +229,7 @@ void del_and_close(SOCKET fd)
        del_impl(i);
        memmove(fds+i, fds+i+1, sizeof(fds[0])*(nfds-(i+1)));
        nfds--;
-#ifndef NETPOLL_USE_LIBUV
+#ifndef HAS_UV
        closesocket(fd);
 #endif
 }