Compile with android NDK

This also fixes the bug that nghttpx's acceptor fd is blocking if
SOCK_NONBLOCK is undefined.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-11 00:28:00 +09:00
parent a86d78216c
commit f7455d48cc
7 changed files with 27 additions and 9 deletions

View File

@ -41,5 +41,6 @@ PATH=$TOOLCHAIN/bin:$PATH
--disable-examples \
--disable-threads \
CPPFLAGS="-I$PREFIX/include" \
CXXFLAGS="-fno-strict-aliasing" \
PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" \
LDFLAGS="-L$PREFIX/lib"

View File

@ -278,7 +278,8 @@ AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ])
# libev (for src)
# libev does not have pkg-config file. Check it in an old way.
LIBS_OLD=$LIBS
AC_CHECK_LIB([ev], [ev_time], [have_libev=yes], [have_libev=no])
# android requires -lm for floor
AC_CHECK_LIB([ev], [ev_time], [have_libev=yes], [have_libev=no], [-lm])
if test "x${have_libev}" = "xyes"; then
AC_CHECK_HEADER([ev.h], [have_libev=yes], [have_libev=no])
if test "x${have_libev}" = "xyes"; then

View File

@ -188,11 +188,19 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
return nullptr;
}
for (rp = res; rp; rp = rp->ai_next) {
#ifdef SOCK_NONBLOCK
fd =
socket(rp->ai_family, rp->ai_socktype | SOCK_NONBLOCK, rp->ai_protocol);
if (fd == -1) {
continue;
}
#else // !SOCK_NONBLOCK
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (fd == -1) {
continue;
}
util::make_socket_nonblocking(fd);
#endif // !SOCK_NONBLOCK
int val = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val,
static_cast<socklen_t>(sizeof(val))) == -1) {

View File

@ -36,14 +36,6 @@
#include "shrpx_log.h"
#ifndef SOCK_NONBLOCK
#define SOCK_NONBLOCK 0
#endif // !SOCK_NONBLOCK
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif // !SOCK_CLOEXEC
#ifndef HAVE__EXIT
#define _Exit(status) _exit(status)
#endif // !HAVE__EXIT

View File

@ -26,6 +26,8 @@
#include <unistd.h>
#include <cerrno>
#include "shrpx_connection_handler.h"
#include "shrpx_config.h"
#include "util.h"

View File

@ -61,11 +61,13 @@ Worker::Worker(SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
http1_connect_blocker_ = util::make_unique<ConnectBlocker>(loop_);
}
#ifndef NOTHREADS
fut_ = std::async(std::launch::async, [this, &ticket_keys] {
worker_config->ticket_keys = ticket_keys;
(void)reopen_log_files();
ev_run(loop_);
});
#endif // !NOTHREADS
}
Worker::~Worker() { ev_async_stop(loop_, &w_); }

View File

@ -34,6 +34,7 @@
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <cerrno>
#include <cassert>
#include <cstdio>
#include <cstring>
@ -860,11 +861,22 @@ int make_socket_nodelay(int fd) {
}
int create_nonblock_socket(int family) {
#ifdef SOCK_NONBLOCK
auto fd = socket(family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
if (fd == -1) {
return -1;
}
#else // !SOCK_NONBLOCK
auto fd = socket(family, SOCK_STREAM, 0);
if (fd == -1) {
return -1;
}
make_socket_nonblocking(fd);
make_socket_closeonexec(fd);
#endif // !SOCK_NONBLOCK
make_socket_nodelay(fd);