diff options
author | Stefano Cristiano <sc@recognitionrobotics.com> | 2019-12-25 17:09:52 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-27 02:19:55 +0100 |
commit | 1222b94ab83658554bf2d9c44d6fa4105041f0a4 (patch) | |
tree | a113def3a0234baf49a5dc50b8be9159b1675dc5 | |
parent | aab412bd8586614bfd480c3725ba523b1029d6a5 (diff) | |
download | serenity-1222b94ab83658554bf2d9c44d6fa4105041f0a4.zip |
LibCore: Allow LibCore to be compiled on macOS host
Compiling LibCore on macOS is needed if one wants to compile host tools
(like IPCCompiler) on a non Linux host.
These changes could be possibly reverted once "event loop" functionality
and "base library" (Vector, String etc.) will be split in two separate libraries,
updating all relevant projects.
-rw-r--r-- | Libraries/LibCore/CEventLoop.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibCore/CLocalServer.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibCore/CLocalSocket.cpp | 13 |
3 files changed, 30 insertions, 0 deletions
diff --git a/Libraries/LibCore/CEventLoop.cpp b/Libraries/LibCore/CEventLoop.cpp index ce983847a4..0f0dbb4b24 100644 --- a/Libraries/LibCore/CEventLoop.cpp +++ b/Libraries/LibCore/CEventLoop.cpp @@ -136,7 +136,14 @@ CEventLoop::CEventLoop() if (!s_main_event_loop) { s_main_event_loop = this; +#if defined(SOCK_NONBLOCK) int rc = pipe2(s_wake_pipe_fds, O_CLOEXEC); +#else + int rc = pipe(s_wake_pipe_fds); + fcntl(s_wake_pipe_fds[0], F_SETFD, FD_CLOEXEC); + fcntl(s_wake_pipe_fds[1], F_SETFD, FD_CLOEXEC); + +#endif ASSERT(rc == 0); s_event_loop_stack->append(this); diff --git a/Libraries/LibCore/CLocalServer.cpp b/Libraries/LibCore/CLocalServer.cpp index 87f1c96df4..ab20d5e299 100644 --- a/Libraries/LibCore/CLocalServer.cpp +++ b/Libraries/LibCore/CLocalServer.cpp @@ -5,6 +5,9 @@ #include <sys/socket.h> #include <sys/stat.h> #include <unistd.h> +#ifndef SOCK_NONBLOCK +#include <sys/ioctl.h> +#endif CLocalServer::CLocalServer(CObject* parent) : CObject(parent) @@ -71,7 +74,14 @@ bool CLocalServer::listen(const String& address) int rc; +#ifdef SOCK_NONBLOCK m_fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); +#else + m_fd = socket(AF_LOCAL, SOCK_STREAM, 0); + int option = 1; + ioctl(m_fd, FIONBIO, &option); + fcntl(m_fd, F_SETFD, FD_CLOEXEC); +#endif ASSERT(m_fd >= 0); auto socket_address = CSocketAddress::local(address); diff --git a/Libraries/LibCore/CLocalSocket.cpp b/Libraries/LibCore/CLocalSocket.cpp index 6a9b195095..8bca8aa9a2 100644 --- a/Libraries/LibCore/CLocalSocket.cpp +++ b/Libraries/LibCore/CLocalSocket.cpp @@ -2,6 +2,10 @@ #include <sys/socket.h> #include <errno.h> +#ifndef SOCK_NONBLOCK +#include <sys/ioctl.h> +#endif + CLocalSocket::CLocalSocket(int fd, CObject* parent) : CSocket(CSocket::Type::Local, parent) { @@ -15,7 +19,16 @@ CLocalSocket::CLocalSocket(int fd, CObject* parent) CLocalSocket::CLocalSocket(CObject* parent) : CSocket(CSocket::Type::Local, parent) { + +#ifdef SOCK_NONBLOCK int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); +#else + int fd = socket(AF_LOCAL, SOCK_STREAM, 0); + int option = 1; + ioctl(fd, FIONBIO, &option); + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif + if (fd < 0) { set_error(errno); } else { |