Skip to content

Instantly share code, notes, and snippets.

@dmatveev
Created June 24, 2011 14:08
Show Gist options
  • Save dmatveev/1044837 to your computer and use it in GitHub Desktop.
Save dmatveev/1044837 to your computer and use it in GitHub Desktop.
EINTR patch
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