Created
June 24, 2011 14:08
-
-
Save dmatveev/1044837 to your computer and use it in GitHub Desktop.
EINTR patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git gio/kqueue/kqueue-thread.c gio/kqueue/kqueue-thread.c | |
index 6781c73..a08534d 100644 | |
--- gio/kqueue/kqueue-thread.c | |
+++ gio/kqueue/kqueue-thread.c | |
@@ -24,6 +24,7 @@ | |
#include <sys/event.h> | |
#include <sys/time.h> | |
#include <unistd.h> | |
+#include <errno.h> | |
#include <glib.h> | |
#include "kqueue-thread.h" | |
@@ -50,6 +51,30 @@ extern int g_kqueue; | |
/** | |
+ * Write n bytes into file descriptor safely | |
+ */ | |
+static gboolean | |
+_safe_write (int fd, gpointer data, gsize size) | |
+{ | |
+ while (size > 0) | |
+ { | |
+ gsize written = write (fd, data, size); | |
+ if (written == -1) | |
+ { | |
+ if (errno == EINTR) | |
+ continue; | |
+ else | |
+ return FALSE; | |
+ } | |
+ size -= written; | |
+ data += written; | |
+ } | |
+ | |
+ return TRUE; | |
+} | |
+ | |
+ | |
+/** | |
* Pick up new file descriptors for monitoring. | |
* | |
* This function will pick up file descriptors from a global list | |
@@ -210,7 +235,7 @@ _kqueue_thread_func (void *arg) | |
kn.fd = received.ident; | |
kn.flags = received.fflags; | |
- write (fd, &kn, sizeof (struct kqueue_notification)); | |
+ _safe_write (fd, &kn, sizeof (struct kqueue_notification)); | |
} | |
} | |
kevents_free (&waiting); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment