From f95743abe80dfafa43db25dfc6edae51a10d83a9 Mon Sep 17 00:00:00 2001 From: Simon Shanks Date: Mon, 15 Jun 2020 09:43:14 +0100 Subject: [PATCH] Event io was blocking socket & holding lock. Fixes #30 --- kfk.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kfk.c b/kfk.c index d0a14e4..7eaa8a4 100644 --- a/kfk.c +++ b/kfk.c @@ -5,6 +5,7 @@ #include #include #include "socketpair.c" +#include #include "k.h" #define K3(f) K f(K x,K y,K z) #define K4(f) K f(K x,K y,K z,K r) @@ -666,6 +667,18 @@ EXP K kfkInit(K UNUSED(x)){ S0=ks(""); if(dumb_socketpair(spair, 1) == SOCKET_ERROR) fprintf(stderr, "Init failed, creating socketpair: %s\n", strerror(errno)); +#ifdef WIN32 + u_long iMode = 1; + if (ioctlsocket(spair[0], FIONBIO, &iMode) != NO_ERROR) + return krr((S)"Init couldn't set socket to non-blocking"); + if (ioctlsocket(spair[1], FIONBIO, &iMode) != NO_ERROR) + return krr((S)"Init couldn't set socket to non-blocking"); +#else + if (fcntl(spair[0], F_SETFL, O_NONBLOCK) == -1) + return krr((S)"Init couldn't set socket to non-blocking"); + if (fcntl(spair[1], F_SETFL, O_NONBLOCK) == -1) + return krr((S)"Init couldn't set socket to non-blocking"); +#endif K r=sd1(-spair[0], &kfkCallback); if(r==0){ fprintf(stderr, "Init failed, adding callback\n");