From f021217cd048b17eed2e63fcc7c29c6f41cf901b Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Sat, 1 Oct 2022 16:36:41 -0400 Subject: [PATCH] zephyr: add zephyr/posix/ prefix to standard headers This is a temporary workaround until the mountain of tech-debt is flattened w.r.t the following: https://github.com/zephyrproject-rtos/zephyr/pull/43987 https://github.com/zephyrproject-rtos/gsoc-2022-thrift/pull/62 https://github.com/zephyrproject-rtos/zephyr/issues/43998 https://github.com/zephyrproject-rtos/zephyr/issues/46910 https://github.com/zephyrproject-rtos/zephyr/issues/45100 but also around the mountain of tech-debt as a result of poor arch/posix software architecture, CONFIG_ARCH_POSIX and CONFIG_POSIX_API incompatibility, and the resultant spillover of moving POSIX definitions into the network subsystem as a result. Fixes zephyrproject-rtos/gsoc-2022-thrift#129 Signed-off-by: Christopher Friedt --- lib/cpp/src/thrift/Thrift.h | 4 +++ lib/cpp/src/thrift/protocol/TProtocol.h | 4 +++ lib/cpp/src/thrift/transport/PlatformSocket.h | 1 + lib/cpp/src/thrift/transport/SocketCommon.h | 8 +++++ .../src/thrift/transport/TServerSocket.cpp | 17 +++++++++++ lib/cpp/src/thrift/transport/TServerSocket.h | 8 +++++ lib/cpp/src/thrift/transport/TSocket.cpp | 29 +++++++++++++++++++ lib/cpp/src/thrift/transport/TSocket.h | 8 +++++ lib/cpp/src/thrift/transport/TSocketUtils.h | 12 ++++++++ 9 files changed, 91 insertions(+) diff --git a/lib/cpp/src/thrift/Thrift.h b/lib/cpp/src/thrift/Thrift.h index d5066ee7107..78f6f6bcd80 100644 --- a/lib/cpp/src/thrift/Thrift.h +++ b/lib/cpp/src/thrift/Thrift.h @@ -29,8 +29,12 @@ #include #ifdef HAVE_NETINET_IN_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_INTTYPES_H #include #endif diff --git a/lib/cpp/src/thrift/protocol/TProtocol.h b/lib/cpp/src/thrift/protocol/TProtocol.h index 114e89a40f6..836bbab10a1 100644 --- a/lib/cpp/src/thrift/protocol/TProtocol.h +++ b/lib/cpp/src/thrift/protocol/TProtocol.h @@ -35,8 +35,12 @@ #include #ifdef HAVE_NETINET_IN_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #include #include #include diff --git a/lib/cpp/src/thrift/transport/PlatformSocket.h b/lib/cpp/src/thrift/transport/PlatformSocket.h index 10df9446e3d..8b6cae68ccc 100644 --- a/lib/cpp/src/thrift/transport/PlatformSocket.h +++ b/lib/cpp/src/thrift/transport/PlatformSocket.h @@ -107,6 +107,7 @@ # define THRIFT_LSEEK lseek # define THRIFT_WRITE write # define THRIFT_READ read +int ioctl(int fd, unsigned long request, ...); # define THRIFT_IOCTL_SOCKET ioctl # define THRIFT_IOCTL_SOCKET_NUM_BYTES_TYPE int # define THRIFT_STAT stat diff --git a/lib/cpp/src/thrift/transport/SocketCommon.h b/lib/cpp/src/thrift/transport/SocketCommon.h index bd1032f726e..20b954ee6d2 100644 --- a/lib/cpp/src/thrift/transport/SocketCommon.h +++ b/lib/cpp/src/thrift/transport/SocketCommon.h @@ -25,8 +25,12 @@ #include #ifdef HAVE_UNISTD_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -34,8 +38,12 @@ #include #endif #ifdef HAVE_SYS_SOCKET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #include diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp index 97fe201c547..9c9f534b97f 100644 --- a/lib/cpp/src/thrift/transport/TServerSocket.cpp +++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp @@ -24,8 +24,12 @@ #include #include #ifdef HAVE_SYS_SOCKET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -33,16 +37,29 @@ #include #endif #ifdef HAVE_NETINET_IN_H +#ifdef __ZEPHYR__ +#include +#include +#else #include #include #endif +#endif #ifdef HAVE_NETDB_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #include #ifdef HAVE_UNISTD_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_SYS_STAT_H #include #endif diff --git a/lib/cpp/src/thrift/transport/TServerSocket.h b/lib/cpp/src/thrift/transport/TServerSocket.h index e826707ac55..84039645ad8 100644 --- a/lib/cpp/src/thrift/transport/TServerSocket.h +++ b/lib/cpp/src/thrift/transport/TServerSocket.h @@ -28,11 +28,19 @@ #include #ifdef HAVE_SYS_SOCKET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_NETDB_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif namespace apache { namespace thrift { diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp index b09f779873e..6c9667ec172 100644 --- a/lib/cpp/src/thrift/transport/TSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSocket.cpp @@ -22,14 +22,30 @@ #include #include #ifdef HAVE_SYS_IOCTL_H +#ifdef __ZEPHYR__ +#include +#include +__attribute__((weak)) +int ioctl(int fd, unsigned long request, ...) +{ + (void)fd; + (void)request; + return -ENOSYS; +} +#else #include +#endif #ifdef __sun #include #endif // __sun #endif #ifdef HAVE_SYS_SOCKET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -38,12 +54,21 @@ #endif #include #ifdef HAVE_NETINET_IN_H +#ifdef __ZEPHYR__ +#include +#include +#else #include #include #endif +#endif #ifdef HAVE_UNISTD_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #include #include @@ -457,8 +482,12 @@ void TSocket::local_open() { if ( #ifdef _WIN32 error == WSANO_DATA +#else +#ifdef __ZEPHYR__ + error == DNS_EAI_NODATA #else error == EAI_NODATA +#endif #endif ) { hints.ai_flags &= ~AI_ADDRCONFIG; diff --git a/lib/cpp/src/thrift/transport/TSocket.h b/lib/cpp/src/thrift/transport/TSocket.h index f14546d9aa7..6b447645a2d 100644 --- a/lib/cpp/src/thrift/transport/TSocket.h +++ b/lib/cpp/src/thrift/transport/TSocket.h @@ -28,14 +28,22 @@ #include #ifdef HAVE_ARPA_INET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_NETDB_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif namespace apache { namespace thrift { diff --git a/lib/cpp/src/thrift/transport/TSocketUtils.h b/lib/cpp/src/thrift/transport/TSocketUtils.h index c9e0e57b882..f09113631e9 100644 --- a/lib/cpp/src/thrift/transport/TSocketUtils.h +++ b/lib/cpp/src/thrift/transport/TSocketUtils.h @@ -27,11 +27,19 @@ #include #ifdef HAVE_SYS_SOCKET_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #ifdef HAVE_NETDB_H +#ifdef __ZEPHYR__ +#include +#else #include #endif +#endif #include @@ -111,8 +119,12 @@ struct AddressResolutionHelper { #ifdef _WIN32 } else { throw std::system_error{THRIFT_GET_SOCKET_ERROR, std::system_category()}; +#else +#ifdef __ZEPHYR__ + } else if (ret == DNS_EAI_SYSTEM) { #else } else if (ret == EAI_SYSTEM) { +#endif throw std::system_error{THRIFT_GET_SOCKET_ERROR, std::system_category()}; } else { throw std::system_error{ret, gai_error()};