Skip to content

Commit

Permalink
Event io was blocking socket & holding lock. Fixes KxSystems#30
Browse files Browse the repository at this point in the history
  • Loading branch information
sshanks-kx committed Jun 15, 2020
1 parent 17f1ca7 commit f95743a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kfk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <librdkafka/rdkafka.h>
#include "socketpair.c"
#include <fcntl.h>
#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)
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit f95743a

Please sign in to comment.