Clean up some NonPosix.h stuff so we can build on Linux.

It appears that SOCK_NONBLOCK is not actually POSIX. According to the
OpenBSD man page, it will be soon, and according to the Linux man page,
it is a Linux extension. However, fcntl() with O_NONBLOCK seems to be
portable across both systems.
This commit is contained in:
Jordan Bancino 2022-10-15 10:08:52 -04:00
parent bb93cae99a
commit 4707f0f4c8
3 changed files with 16 additions and 11 deletions

View File

@ -41,6 +41,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
struct HttpServer
{
@ -310,13 +311,18 @@ HttpServerCreate(unsigned short port, unsigned int nThreads, unsigned int maxCon
goto error;
}
server->sd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
server->sd = socket(AF_INET, SOCK_STREAM, 0);
if (server->sd < 0)
{
goto error;
}
if (fcntl(server->sd, F_SETFL, O_NONBLOCK) == -1)
{
goto error;
}
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = htonl(INADDR_ANY);

View File

@ -23,6 +23,7 @@
*/
#include <Log.h>
#include <NonPosix.h>
#include <Memory.h>
#include <string.h>

View File

@ -30,6 +30,8 @@
#ifndef TELODENDRIA_NONPOSIX_H
#define TELODENDRIA_NONPOSIX_H
#include <stdarg.h>
/*
* Pretty much all Unix-like systems have a chroot() function. In fact,
* chroot() used to be POSIX, so any operating system claiming to be
@ -40,6 +42,12 @@
*/
extern int chroot(const char *);
/*
* Pretty much every syslog interface has a vsyslog(). Unfortuntately,
* it is not POSIX.
*/
extern void vsyslog(int, const char *, va_list);
/*
* Telodendria is primarily developed on OpenBSD; as such, you can
* expect that it will use some OpenBSD-specific features if OpenBSD
@ -53,16 +61,6 @@ extern int chroot(const char *);
#ifdef __OpenBSD__
extern int pledge(const char *, const char *);
extern int unveil(const char *, const char *);
/*
* OpenBSD requires that _BSD_SOURCE be set to use SOCK_NONBLOCK for
* some reason, even though from everything I can tell, SOCK_NONBLOCK
* is POSIX.
*/
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#endif
#endif