Commit 13c52b82 authored by Kenton Varda's avatar Kenton Varda

Support Android.

parent 177fb269
...@@ -343,7 +343,7 @@ int mkstemp(char *tpl) { ...@@ -343,7 +343,7 @@ int mkstemp(char *tpl) {
#endif #endif
TEST(Serialize, FileDescriptors) { TEST(Serialize, FileDescriptors) {
#if _WIN32 #if _WIN32 || __ANDROID__
// TODO(cleanup): Find the Windows temp directory? Seems overly difficult. // TODO(cleanup): Find the Windows temp directory? Seems overly difficult.
char filename[] = "capnproto-serialize-test-XXXXXX"; char filename[] = "capnproto-serialize-test-XXXXXX";
#else #else
......
...@@ -99,16 +99,20 @@ TEST(AsyncIo, AddressParsing) { ...@@ -99,16 +99,20 @@ TEST(AsyncIo, AddressParsing) {
EXPECT_EQ("unix:foo/bar/baz", tryParse(w, network, "unix:foo/bar/baz")); EXPECT_EQ("unix:foo/bar/baz", tryParse(w, network, "unix:foo/bar/baz"));
// We can parse services by name... // We can parse services by name...
#if !__ANDROID__ // Service names not supported on Android for some reason?
EXPECT_EQ("1.2.3.4:80", tryParse(w, network, "1.2.3.4:http", 5678)); EXPECT_EQ("1.2.3.4:80", tryParse(w, network, "1.2.3.4:http", 5678));
EXPECT_EQ("*:80", tryParse(w, network, "*:http", 5678)); EXPECT_EQ("*:80", tryParse(w, network, "*:http", 5678));
#endif
// IPv6 tests. Annoyingly, these don't work on machines that don't have IPv6 configured on any // IPv6 tests. Annoyingly, these don't work on machines that don't have IPv6 configured on any
// interfaces. // interfaces.
if (hasIpv6()) { if (hasIpv6()) {
EXPECT_EQ("[::]:123", tryParse(w, network, "0::0", 123)); EXPECT_EQ("[::]:123", tryParse(w, network, "0::0", 123));
EXPECT_EQ("[12ab:cd::34]:321", tryParse(w, network, "[12ab:cd:0::0:34]:321", 432)); EXPECT_EQ("[12ab:cd::34]:321", tryParse(w, network, "[12ab:cd:0::0:34]:321", 432));
#if !__ANDROID__ // Service names not supported on Android for some reason?
EXPECT_EQ("[::]:80", tryParse(w, network, "[::]:http", 5678)); EXPECT_EQ("[::]:80", tryParse(w, network, "[::]:http", 5678));
EXPECT_EQ("[12ab:cd::34]:80", tryParse(w, network, "[12ab:cd::34]:http", 5678)); EXPECT_EQ("[12ab:cd::34]:80", tryParse(w, network, "[12ab:cd::34]:http", 5678));
#endif
} }
// It would be nice to test DNS lookup here but the test would not be very hermetic. Even // It would be nice to test DNS lookup here but the test would not be very hermetic. Even
......
...@@ -61,7 +61,7 @@ void setCloseOnExec(int fd) { ...@@ -61,7 +61,7 @@ void setCloseOnExec(int fd) {
} }
static constexpr uint NEW_FD_FLAGS = static constexpr uint NEW_FD_FLAGS =
#if __linux__ #if __linux__ && !__BIONIC__
LowLevelAsyncIoProvider::ALREADY_CLOEXEC | LowLevelAsyncIoProvider::ALREADY_NONBLOCK | LowLevelAsyncIoProvider::ALREADY_CLOEXEC | LowLevelAsyncIoProvider::ALREADY_NONBLOCK |
#endif #endif
LowLevelAsyncIoProvider::TAKE_OWNERSHIP; LowLevelAsyncIoProvider::TAKE_OWNERSHIP;
...@@ -344,7 +344,7 @@ public: ...@@ -344,7 +344,7 @@ public:
bool isStream = type == SOCK_STREAM; bool isStream = type == SOCK_STREAM;
int result; int result;
#if __linux__ #if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC; type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif #endif
KJ_SYSCALL(result = ::socket(addr.generic.sa_family, type, 0)); KJ_SYSCALL(result = ::socket(addr.generic.sa_family, type, 0));
...@@ -644,7 +644,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost( ...@@ -644,7 +644,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
// a custom DNS resolver... // a custom DNS resolver...
int fds[2]; int fds[2];
#if __linux__ #if __linux__ && !__BIONIC__
KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC)); KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC));
#else #else
KJ_SYSCALL(pipe(fds)); KJ_SYSCALL(pipe(fds));
...@@ -736,7 +736,7 @@ public: ...@@ -736,7 +736,7 @@ public:
int newFd; int newFd;
retry: retry:
#if __linux__ #if __linux__ && !__BIONIC__
newFd = ::accept4(fd, nullptr, nullptr, SOCK_NONBLOCK | SOCK_CLOEXEC); newFd = ::accept4(fd, nullptr, nullptr, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else #else
newFd = ::accept(fd, nullptr, nullptr); newFd = ::accept(fd, nullptr, nullptr);
...@@ -964,7 +964,7 @@ public: ...@@ -964,7 +964,7 @@ public:
OneWayPipe newOneWayPipe() override { OneWayPipe newOneWayPipe() override {
int fds[2]; int fds[2];
#if __linux__ #if __linux__ && !__BIONIC__
KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC)); KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC));
#else #else
KJ_SYSCALL(pipe(fds)); KJ_SYSCALL(pipe(fds));
...@@ -978,7 +978,7 @@ public: ...@@ -978,7 +978,7 @@ public:
TwoWayPipe newTwoWayPipe() override { TwoWayPipe newTwoWayPipe() override {
int fds[2]; int fds[2];
int type = SOCK_STREAM; int type = SOCK_STREAM;
#if __linux__ #if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC; type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif #endif
KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds)); KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds));
...@@ -996,7 +996,7 @@ public: ...@@ -996,7 +996,7 @@ public:
Function<void(AsyncIoProvider&, AsyncIoStream&, WaitScope&)> startFunc) override { Function<void(AsyncIoProvider&, AsyncIoStream&, WaitScope&)> startFunc) override {
int fds[2]; int fds[2];
int type = SOCK_STREAM; int type = SOCK_STREAM;
#if __linux__ #if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC; type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif #endif
KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds)); KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds));
......
...@@ -65,12 +65,14 @@ TEST_F(AsyncUnixTest, Signals) { ...@@ -65,12 +65,14 @@ TEST_F(AsyncUnixTest, Signals) {
EXPECT_SI_CODE(SI_USER, info.si_code); EXPECT_SI_CODE(SI_USER, info.si_code);
} }
#ifdef SIGRTMIN #if defined(SIGRTMIN) && !__BIONIC__
TEST_F(AsyncUnixTest, SignalWithValue) { TEST_F(AsyncUnixTest, SignalWithValue) {
// This tests that if we use sigqueue() to attach a value to the signal, that value is received // This tests that if we use sigqueue() to attach a value to the signal, that value is received
// correctly. Note that this only works on platforms that support real-time signals -- even // correctly. Note that this only works on platforms that support real-time signals -- even
// though the signal we're sending is SIGURG, the sigqueue() system call is introduced by RT // though the signal we're sending is SIGURG, the sigqueue() system call is introduced by RT
// signals. Hence this test won't run on e.g. Mac OSX. // signals. Hence this test won't run on e.g. Mac OSX.
//
// Also, Android's bionic does not appear to support sigqueue() even though the kernel does.
UnixEventPort port; UnixEventPort port;
EventLoop loop(port); EventLoop loop(port);
...@@ -92,6 +94,8 @@ TEST_F(AsyncUnixTest, SignalWithPointerValue) { ...@@ -92,6 +94,8 @@ TEST_F(AsyncUnixTest, SignalWithPointerValue) {
// correctly. Note that this only works on platforms that support real-time signals -- even // correctly. Note that this only works on platforms that support real-time signals -- even
// though the signal we're sending is SIGURG, the sigqueue() system call is introduced by RT // though the signal we're sending is SIGURG, the sigqueue() system call is introduced by RT
// signals. Hence this test won't run on e.g. Mac OSX. // signals. Hence this test won't run on e.g. Mac OSX.
//
// Also, Android's bionic does not appear to support sigqueue() even though the kernel does.
UnixEventPort port; UnixEventPort port;
EventLoop loop(port); EventLoop loop(port);
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
#include "io.h" #include "io.h"
#include <signal.h> #include <signal.h>
#if __linux__ && !defined(KJ_USE_EPOLL) #if __linux__ && !__BIONIC__ && !defined(KJ_USE_EPOLL)
// Default to epoll on Linux, except on Bionic (Android) which doesn't have signalfd.h.
#define KJ_USE_EPOLL 1 #define KJ_USE_EPOLL 1
#endif #endif
......
...@@ -33,6 +33,18 @@ ...@@ -33,6 +33,18 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <linux/futex.h> #include <linux/futex.h>
#include <limits.h> #include <limits.h>
#ifndef SYS_futex
// Missing on Android/Bionic.
#define SYS_futex __NR_futex
#endif
#ifndef FUTEX_WAIT_PRIVATE
// Missing on Android/Bionic.
#define FUTEX_WAIT_PRIVATE FUTEX_WAIT
#define FUTEX_WAKE_PRIVATE FUTEX_WAKE
#endif
#elif _WIN32 #elif _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment