From dd315fb0f7a90a6f154cbea0e7a7c64b550164b9 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Wed, 10 Sep 2014 19:56:26 +0200 Subject: [PATCH] readpipe/writepite/closepipe for fake pipes on Windows --- src/compat/windows/wincompat.h | 5 +++++ src/internal.h | 3 +++ src/simple-watch.c | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compat/windows/wincompat.h b/src/compat/windows/wincompat.h index 8f62240..f611e33 100644 --- a/src/compat/windows/wincompat.h +++ b/src/compat/windows/wincompat.h @@ -99,6 +99,11 @@ int ioctl(int d, unsigned long request, int *p); // something to give to WSAPoll, so we fake it with a local TCP socket. (ugh) int pipe(int pipefd[2]); +// pipe(socket)-specific read/write/close equivalents +#define closepipe closesocket +#define writepipe(s,buf,len) send(s, buf, len, 0) +#define readpipe(s,buf,len) recv(s, buf, len, 0) + // Windows logically doesn't have uname, so we supply a replacement. diff --git a/src/internal.h b/src/internal.h index 019006e..59eca2a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -50,6 +50,9 @@ typedef struct CattaEntry CattaEntry; #ifndef _WIN32 #define closesocket close +#define closepipe close +#define writepipe write +#define readpipe read #define winsock_init() #define winsock_exit() #define errnostrsocket() strerror(errno) diff --git a/src/simple-watch.c b/src/simple-watch.c index 7a0052d..7719e56 100644 --- a/src/simple-watch.c +++ b/src/simple-watch.c @@ -100,7 +100,7 @@ void catta_simple_poll_wakeup(CattaSimplePoll *s) { char c = 'W'; assert(s); - write(s->wakeup_pipe[1], &c, sizeof(c)); + writepipe(s->wakeup_pipe[1], &c, sizeof(c)); s->wakeup_issued = 1; } @@ -113,7 +113,7 @@ static void clear_wakeup(CattaSimplePoll *s) { s->wakeup_issued = 0; for(;;) - if (read(s->wakeup_pipe[0], &c, sizeof(c)) != sizeof(c)) + if (readpipe(s->wakeup_pipe[0], c, sizeof(c)) != sizeof(c)) break; } @@ -364,10 +364,10 @@ void catta_simple_poll_free(CattaSimplePoll *s) { catta_free(s->pollfds); if (s->wakeup_pipe[0] >= 0) - closesocket(s->wakeup_pipe[0]); + closepipe(s->wakeup_pipe[0]); if (s->wakeup_pipe[1] >= 0) - closesocket(s->wakeup_pipe[1]); + closepipe(s->wakeup_pipe[1]); catta_free(s); winsock_exit(); // match the winsock_init in catta_simple_poll_new -- 2.39.5