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

Support Android.

parent 177fb269
......@@ -343,7 +343,7 @@ int mkstemp(char *tpl) {
#endif
TEST(Serialize, FileDescriptors) {
#if _WIN32
#if _WIN32 || __ANDROID__
// TODO(cleanup): Find the Windows temp directory? Seems overly difficult.
char filename[] = "capnproto-serialize-test-XXXXXX";
#else
......
......@@ -99,16 +99,20 @@ TEST(AsyncIo, AddressParsing) {
EXPECT_EQ("unix:foo/bar/baz", tryParse(w, network, "unix:foo/bar/baz"));
// 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("*:80", tryParse(w, network, "*:http", 5678));
#endif
// IPv6 tests. Annoyingly, these don't work on machines that don't have IPv6 configured on any
// interfaces.
if (hasIpv6()) {
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));
#if !__ANDROID__ // Service names not supported on Android for some reason?
EXPECT_EQ("[::]:80", tryParse(w, network, "[::]: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
......
......@@ -61,7 +61,7 @@ void setCloseOnExec(int fd) {
}
static constexpr uint NEW_FD_FLAGS =
#if __linux__
#if __linux__ && !__BIONIC__
LowLevelAsyncIoProvider::ALREADY_CLOEXEC | LowLevelAsyncIoProvider::ALREADY_NONBLOCK |
#endif
LowLevelAsyncIoProvider::TAKE_OWNERSHIP;
......@@ -344,7 +344,7 @@ public:
bool isStream = type == SOCK_STREAM;
int result;
#if __linux__
#if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif
KJ_SYSCALL(result = ::socket(addr.generic.sa_family, type, 0));
......@@ -644,7 +644,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
// a custom DNS resolver...
int fds[2];
#if __linux__
#if __linux__ && !__BIONIC__
KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC));
#else
KJ_SYSCALL(pipe(fds));
......@@ -736,7 +736,7 @@ public:
int newFd;
retry:
#if __linux__
#if __linux__ && !__BIONIC__
newFd = ::accept4(fd, nullptr, nullptr, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else
newFd = ::accept(fd, nullptr, nullptr);
......@@ -964,7 +964,7 @@ public:
OneWayPipe newOneWayPipe() override {
int fds[2];
#if __linux__
#if __linux__ && !__BIONIC__
KJ_SYSCALL(pipe2(fds, O_NONBLOCK | O_CLOEXEC));
#else
KJ_SYSCALL(pipe(fds));
......@@ -978,7 +978,7 @@ public:
TwoWayPipe newTwoWayPipe() override {
int fds[2];
int type = SOCK_STREAM;
#if __linux__
#if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif
KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds));
......@@ -996,7 +996,7 @@ public:
Function<void(AsyncIoProvider&, AsyncIoStream&, WaitScope&)> startFunc) override {
int fds[2];
int type = SOCK_STREAM;
#if __linux__
#if __linux__ && !__BIONIC__
type |= SOCK_NONBLOCK | SOCK_CLOEXEC;
#endif
KJ_SYSCALL(socketpair(AF_UNIX, type, 0, fds));
......
......@@ -65,12 +65,14 @@ TEST_F(AsyncUnixTest, Signals) {
EXPECT_SI_CODE(SI_USER, info.si_code);
}
#ifdef SIGRTMIN
#if defined(SIGRTMIN) && !__BIONIC__
TEST_F(AsyncUnixTest, SignalWithValue) {
// 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
// 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.
//
// Also, Android's bionic does not appear to support sigqueue() even though the kernel does.
UnixEventPort port;
EventLoop loop(port);
......@@ -92,6 +94,8 @@ TEST_F(AsyncUnixTest, SignalWithPointerValue) {
// 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
// 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;
EventLoop loop(port);
......
......@@ -32,7 +32,8 @@
#include "io.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
#endif
......
......@@ -33,6 +33,18 @@
#include <sys/syscall.h>
#include <linux/futex.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
#include <windows.h>
#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