diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-29 16:17:58 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-29 16:17:58 +0200 |
commit | 9a86ce6ea990ac72337bffb78f663f8a904a408f (patch) | |
tree | b532fb296850eab0598d89452373170c9b4c1c1a /src/fastd.h | |
parent | 639ebc2ff93adca5eb9e12d70a2e9e19731c84ba (diff) | |
download | fastd-9a86ce6ea990ac72337bffb78f663f8a904a408f.tar fastd-9a86ce6ea990ac72337bffb78f663f8a904a408f.zip |
Fold fastd_open_pipe into fastd_async_init, simpify fastd_setfl and fastd_setfd and move to fastd.h
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 24 |
1 files changed, 20 insertions, 4 deletions
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 <errno.h> +#include <fcntl.h> #include <poll.h> #include <stdarg.h> #include <stddef.h> @@ -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)); \ |