From 9a86ce6ea990ac72337bffb78f663f8a904a408f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 29 Apr 2014 16:17:58 +0200 Subject: Fold fastd_open_pipe into fastd_async_init, simpify fastd_setfl and fastd_setfd and move to fastd.h --- src/async.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/async.c') diff --git a/src/async.c b/src/async.c index ed8370f..2343cbb 100644 --- a/src/async.c +++ b/src/async.c @@ -27,8 +27,6 @@ #include "async.h" #include "fastd.h" -#include - typedef struct fastd_async_hdr { fastd_async_type_t type; @@ -37,8 +35,18 @@ typedef struct fastd_async_hdr { void fastd_async_init(void) { - fastd_open_pipe(&ctx.async_rfd, &ctx.async_wfd); - fastd_setfl(ctx.async_wfd, O_NONBLOCK, 0); + int fds[2]; + + /* use socketpair with SOCK_DGRAM instead of pipe2 with O_DIRECT to keep this portable */ + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds)) + exit_errno("socketpair"); + + fastd_setfd(fds[0], FD_CLOEXEC); + fastd_setfd(fds[1], FD_CLOEXEC); + fastd_setfl(fds[1], O_NONBLOCK); + + ctx.async_rfd = fds[0]; + ctx.async_wfd = fds[1]; } static void handle_resolve_return(const fastd_async_resolve_return_t *resolve_return) { -- cgit v1.2.3