aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-05-30 11:53:44 -0700
committerGarrett D'Amore <garrett@damore.org>2018-05-30 11:53:44 -0700
commitbcbb36cd4fee89ba86dc1028b9f4de928d361abe (patch)
treeb1c45912b99ef7586adbe27a764c582ed3311578 /src/platform/posix
parentf01e2c82f236b405b95adbe517a3cc9b41d17f16 (diff)
downloadnng-bcbb36cd4fee89ba86dc1028b9f4de928d361abe.tar.gz
nng-bcbb36cd4fee89ba86dc1028b9f4de928d361abe.tar.bz2
nng-bcbb36cd4fee89ba86dc1028b9f4de928d361abe.zip
fixes #477 Android NDK build configuration
This enables the software to be built for Android, going back to at least Android SDK r15 (IceCreamSandwich) and at least up to SDK r27 (Oreo). Older versions of Android may work, but we have no way to build them to test. While here we have changed our CMake configuration to disable building tools or tests when we detect a cross-compile situation. Documentation for cross-compilation is updated as well.
Diffstat (limited to 'src/platform/posix')
-rw-r--r--src/platform/posix/posix_file.c19
-rw-r--r--src/platform/posix/posix_pollq_epoll.c9
2 files changed, 27 insertions, 1 deletions
diff --git a/src/platform/posix/posix_file.c b/src/platform/posix/posix_file.c
index 83d045fa..b1da3cd5 100644
--- a/src/platform/posix/posix_file.c
+++ b/src/platform/posix/posix_file.c
@@ -22,6 +22,11 @@
#include <sys/types.h>
#include <unistd.h>
+// Some systems -- Android -- have BSD flock but not POSIX lockf.
+#if defined(NNG_HAVE_FLOCK) && !defined(NNG_HAVE_LOCKF)
+#include <sys/file.h>
+#endif
+
// File support.
static int
@@ -264,10 +269,22 @@ int
nni_plat_file_lock(const char *path, nni_plat_flock *lk)
{
int fd;
+ int rv;
if ((fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
return (nni_plat_errno(errno));
}
- if (lockf(fd, F_TLOCK, 0) < 0) {
+#ifdef NNG_HAVE_LOCKF
+ rv = lockf(fd, F_TLOCK, 0);
+#elif defined NNG_HAVE_FLOCK
+ rv = flock(fd, LOCK_EX | LOCK_NB);
+#else
+ // We don't have locking support. This means you live dangerously.
+ // For example, ZeroTier cannot be sure that nothing else is using
+ // the same configuration file. If you're here, its probably an
+ // embedded scenario, and we can live with it.
+ rv = 0;
+#endif
+ if (rv < 0) {
int rv = errno;
close(fd);
if (rv == EAGAIN) {
diff --git a/src/platform/posix/posix_pollq_epoll.c b/src/platform/posix/posix_pollq_epoll.c
index 9c1ae682..e4f9ddb6 100644
--- a/src/platform/posix/posix_pollq_epoll.c
+++ b/src/platform/posix/posix_pollq_epoll.c
@@ -348,9 +348,18 @@ nni_posix_pollq_create(nni_posix_pollq *pq)
{
int rv;
+#if NNG_HAVE_EPOLL_CREATE1
if ((pq->epfd = epoll_create1(EPOLL_CLOEXEC)) < 0) {
return (nni_plat_errno(errno));
}
+#else
+ // Old Linux. Size is a "hint" about number of descriptors.
+ // Hopefully not a hard limit, and not used in modern Linux.
+ if ((pq->epfd = epoll_create(16)) < 0) {
+ return (nni_plat_errno(errno));
+ }
+ (void) fcntl(pq->epfd, F_SETFD, FD_CLOEXEC);
+#endif
pq->close = false;