]> git.meshlink.io Git - catta/commitdiff
readpipe/writepite/closepipe for fake pipes on Windows
authorSven M. Hallberg <pesco@khjk.org>
Wed, 10 Sep 2014 17:56:26 +0000 (19:56 +0200)
committerSven M. Hallberg <pesco@khjk.org>
Wed, 10 Sep 2014 17:56:26 +0000 (19:56 +0200)
src/compat/windows/wincompat.h
src/internal.h
src/simple-watch.c

index 8f62240c68be2e3cc9f9c57bfc1b98f283d503a2..f611e33e581534346e81022dafb3f83759c87084 100644 (file)
@@ -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.
 
index 019006e71cad816ab674c020735950c65d81e41a..59eca2ad34ed70a54ebc30aadb05c17b87a62e8f 100644 (file)
@@ -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)
index 7a0052d5e915b9eb0166f32061d04b2bf3818ada..7719e56cb0e43b557d9f173f6b40e951dc484cad 100644 (file)
@@ -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