Enable vsock support for Android

The existing code fails to enable vsock on Android because it tries to
enable vsock on Android when:

a) a certain Linux version is detected
b) and a certain libc is present.

For a), it requires that `<linux/version.h>` is included.

For b), Android does not use glibc. Instead `AF_VSOCK` is included since
NDK version 14.

This commit fixes both issues by including the needed Linux header and
detecting the `__NDK_MAJOR__` version.

For context, AOSP, has it always enabled:
06fb97455f%5E%21/src/core/lib/iomgr/port.h

But this patch compiles with older NDK version and/or older Linux
versions, in case someone is still using them.
pull/37733/head
Ricardo Quesada 2 months ago
parent 4ffcdd4ab7
commit 9b27187337
  1. 6
      include/grpc/support/port_platform.h
  2. 4
      src/core/lib/iomgr/port.h

@ -194,6 +194,12 @@
#define GPR_HAS_PTHREAD_H 1 #define GPR_HAS_PTHREAD_H 1
#define GPR_GETPID_IN_UNISTD_H 1 #define GPR_GETPID_IN_UNISTD_H 1
#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
#if defined(__has_include)
#if __has_include(<android/ndk-version.h>)
#include <android/ndk-version.h>
#endif /* __has_include(<android/ndk-version.h>) */
#endif /* defined(__has_include) */
#include <linux/version.h>
#elif defined(__linux__) #elif defined(__linux__)
#define GPR_PLATFORM_STRING "linux" #define GPR_PLATFORM_STRING "linux"
#ifndef _BSD_SOURCE #ifndef _BSD_SOURCE

@ -40,8 +40,8 @@
#define GRPC_HAVE_IP_PKTINFO 1 #define GRPC_HAVE_IP_PKTINFO 1
#define GRPC_HAVE_MSG_NOSIGNAL 1 #define GRPC_HAVE_MSG_NOSIGNAL 1
#define GRPC_HAVE_UNIX_SOCKET 1 #define GRPC_HAVE_UNIX_SOCKET 1
#if defined(LINUX_VERSION_CODE) && defined(__GLIBC_PREREQ) #if defined(LINUX_VERSION_CODE) && defined(__NDK_MAJOR__)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) && __GLIBC_PREREQ(2, 18) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) && __NDK_MAJOR__ >= 14
#define GRPC_HAVE_VSOCK 1 #define GRPC_HAVE_VSOCK 1
#endif #endif
#endif #endif

Loading…
Cancel
Save