summaryrefslogtreecommitdiff
path: root/src/core/async.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-05-02 17:56:05 +0200
committerLennart Poettering <lennart@poettering.net>2014-05-02 17:57:37 +0200
commit8a474b0c04a5a3608dda53edc1ddaa932ba177bf (patch)
tree70812ec99f9d7a078de1f2af7c91a99639cb65be /src/core/async.c
parent7348b3adb324614132cf376f478e883bd7de28f1 (diff)
async: add asynchronous close() call
Diffstat (limited to 'src/core/async.c')
-rw-r--r--src/core/async.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/async.c b/src/core/async.c
index af527bea4e..3876deda70 100644
--- a/src/core/async.c
+++ b/src/core/async.c
@@ -24,6 +24,7 @@
#include "async.h"
#include "log.h"
+#include "util.h"
int asynchronous_job(void* (*func)(void *p), void *arg) {
pthread_attr_t a;
@@ -70,3 +71,24 @@ int asynchronous_sync(void) {
return asynchronous_job(sync_thread, NULL);
}
+
+static void *close_thread(void *p) {
+ safe_close(PTR_TO_INT(p));
+ return NULL;
+}
+
+int asynchronous_close(int fd) {
+ int r;
+
+ /* This is supposed to behave similar to safe_close(), but
+ * actually invoke close() asynchronously, so that it will
+ * never block. Ideally the kernel would have an API for this,
+ * but it doesn't, so we work around it, and hide this as a
+ * far away as we can. */
+
+ r = asynchronous_job(close_thread, INT_TO_PTR(fd));
+ if (r < 0)
+ safe_close(fd);
+
+ return -1;
+}