[misc] Define SOCK_NONBLOCK and SOCK_CLOEXEC if platform doesn't

This commit is contained in:
ejurgensen 2021-04-01 01:45:09 +02:00
parent 64d6b0d4c3
commit 790c9dcca9
2 changed files with 9 additions and 8 deletions

View File

@ -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;

View File

@ -16,6 +16,15 @@
#include <netinet/in.h>
#include <event2/http.h>
#ifndef SOCK_NONBLOCK
#include <fcntl.h>
#define SOCK_NONBLOCK O_NONBLOCK
#endif
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif
union net_sockaddr
{
struct sockaddr_in sin;