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/fastd.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/fastd.h') diff --git a/src/fastd.h b/src/fastd.h index 6666d70..73c7229 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -34,6 +34,7 @@ #include "vector.h" #include +#include #include #include #include @@ -310,10 +311,6 @@ fastd_socket_t* fastd_socket_open(fastd_peer_t *peer, int af); void fastd_socket_close(fastd_socket_t *sock); void fastd_socket_error(fastd_socket_t *sock); -void fastd_open_pipe(int *readfd, int *writefd); -void fastd_setfd(const int fd, int set, int unset); -void fastd_setfl(const int fd, int set, int unset); - void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote); void fastd_tuntap_open(void); @@ -332,6 +329,25 @@ static inline int fastd_rand(int min, int max) { } +static inline void fastd_setfd(const int fd, int set) { + int flags = fcntl(fd, F_GETFD); + if (flags < 0) + exit_errno("Getting file descriptor flags failed: fcntl"); + + if (fcntl(fd, F_SETFD, flags|set) < 0) + exit_errno("Setting file descriptor flags failed: fcntl"); +} + +static inline void fastd_setfl(const int fd, int set) { + int flags = fcntl(fd, F_GETFL); + if (flags < 0) + exit_errno("Getting file status flags failed: fcntl"); + + if (fcntl(fd, F_SETFL, flags|set) < 0) + exit_errno("Setting file status flags failed: fcntl"); +} + + #define container_of(ptr, type, member) ({ \ const __typeof__(((type *)0)->member) *_mptr = (ptr); \ (type*)((char*)_mptr - offsetof(type, member)); \ -- cgit v1.2.3