From 790c9dcca9487c0d6f0498a5dac5050d802e92c6 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 1 Apr 2021 01:45:09 +0200 Subject: [PATCH] [misc] Define SOCK_NONBLOCK and SOCK_CLOEXEC if platform doesn't --- src/misc.c | 8 -------- src/misc.h | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/misc.c b/src/misc.c index 569079d5..a615adda 100644 --- a/src/misc.c +++ b/src/misc.c @@ -205,11 +205,7 @@ net_connect(const char *addr, unsigned short port, int type, const char *log_ser for (ptr = servinfo; ptr; ptr = ptr->ai_next) { -#ifdef SOCK_CLOEXEC fd = socket(ptr->ai_family, type | SOCK_CLOEXEC, ptr->ai_protocol); -#else - fd = socket(ptr->ai_family, type, ptr->ai_protocol); -#endif if (fd < 0) { continue; @@ -273,11 +269,7 @@ net_bind(short unsigned *port, int type, const char *log_service_name) if (fd >= 0) close(fd); -#ifdef SOCK_CLOEXEC fd = socket(ptr->ai_family, type | SOCK_CLOEXEC, ptr->ai_protocol); -#else - fd = socket(ptr->ai_family, type, ptr->ai_protocol); -#endif if (fd < 0) continue; diff --git a/src/misc.h b/src/misc.h index 53ba4280..893f7362 100644 --- a/src/misc.h +++ b/src/misc.h @@ -16,6 +16,15 @@ #include #include +#ifndef SOCK_NONBLOCK +#include +#define SOCK_NONBLOCK O_NONBLOCK +#endif + +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC 0 +#endif + union net_sockaddr { struct sockaddr_in sin;