Skip to content

Commit

Permalink
zephyr: add zephyr/posix/ prefix to standard headers
Browse files Browse the repository at this point in the history
This is a temporary workaround until the mountain of
tech-debt is flattened w.r.t the following:

zephyrproject-rtos/zephyr#43987
zephyrproject-rtos/gsoc-2022-thrift#62
zephyrproject-rtos/zephyr#43998
zephyrproject-rtos/zephyr#46910
zephyrproject-rtos/zephyr#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 <cfriedt@meta.com>
  • Loading branch information
cfriedt committed Oct 1, 2022
1 parent 12fe884 commit c31244d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cpp/src/thrift/Thrift.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@

#include <sys/types.h>
#ifdef HAVE_NETINET_IN_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netinet/in.h>
#else
#include <netinet/in.h>
#endif
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
Expand Down
4 changes: 4 additions & 0 deletions lib/cpp/src/thrift/protocol/TProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
#include <memory>

#ifdef HAVE_NETINET_IN_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netinet/in.h>
#else
#include <netinet/in.h>
#endif
#endif
#include <sys/types.h>
#include <string>
#include <map>
Expand Down
1 change: 1 addition & 0 deletions lib/cpp/src/thrift/transport/PlatformSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/cpp/src/thrift/transport/SocketCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,25 @@
#include <thrift/thrift-config.h>

#ifdef HAVE_UNISTD_H
#ifdef __ZEPHYR__
#include <zephyr/posix/unistd.h>
#else
#include <unistd.h>
#endif
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#ifdef HAVE_AF_UNIX_H
#include <afunix.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/sys/socket.h>
#else
#include <sys/socket.h>
#endif
#endif

#include <string>

Expand Down
17 changes: 17 additions & 0 deletions lib/cpp/src/thrift/transport/TServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,42 @@
#include <stdexcept>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/sys/socket.h>
#else
#include <sys/socket.h>
#endif
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
#ifdef HAVE_NETINET_IN_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netinet/in.h>
#include <zephyr/posix/netinet/tcp.h>
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#endif
#ifdef HAVE_NETDB_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netdb.h>
#else
#include <netdb.h>
#endif
#endif
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#ifdef __ZEPHYR__
#include <zephyr/posix/unistd.h>
#else
#include <unistd.h>
#endif
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
Expand Down
8 changes: 8 additions & 0 deletions lib/cpp/src/thrift/transport/TServerSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@

#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/sys/socket.h>
#else
#include <sys/socket.h>
#endif
#endif
#ifdef HAVE_NETDB_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netdb.h>
#else
#include <netdb.h>
#endif
#endif

namespace apache {
namespace thrift {
Expand Down
29 changes: 29 additions & 0 deletions lib/cpp/src/thrift/transport/TSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,30 @@
#include <cstring>
#include <sstream>
#ifdef HAVE_SYS_IOCTL_H
#ifdef __ZEPHYR__
#include <errno.h>
#include <zephyr/posix/sys/ioctl.h>
__attribute__((weak))
int ioctl(int fd, unsigned long request, ...)
{
(void)fd;
(void)request;
return -ENOSYS;
}
#else
#include <sys/ioctl.h>
#endif
#ifdef __sun
#include <sys/filio.h>
#endif // __sun
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/sys/socket.h>
#else
#include <sys/socket.h>
#endif
#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
Expand All @@ -38,12 +54,21 @@
#endif
#include <sys/types.h>
#ifdef HAVE_NETINET_IN_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netinet/in.h>
#include <zephyr/posix/netinet/tcp.h>
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#endif
#ifdef HAVE_UNISTD_H
#ifdef __ZEPHYR__
#include <zephyr/posix/unistd.h>
#else
#include <unistd.h>
#endif
#endif
#include <fcntl.h>

#include <thrift/concurrency/Monitor.h>
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions lib/cpp/src/thrift/transport/TSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@
#include <thrift/transport/PlatformSocket.h>

#ifdef HAVE_ARPA_INET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/arpa/inet.h>
#else
#include <arpa/inet.h>
#endif
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_NETDB_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netdb.h>
#else
#include <netdb.h>
#endif
#endif

namespace apache {
namespace thrift {
Expand Down
12 changes: 12 additions & 0 deletions lib/cpp/src/thrift/transport/TSocketUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@

#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#ifdef __ZEPHYR__
#include <zephyr/posix/sys/socket.h>
#else
#include <sys/socket.h>
#endif
#endif
#ifdef HAVE_NETDB_H
#ifdef __ZEPHYR__
#include <zephyr/posix/netdb.h>
#else
#include <netdb.h>
#endif
#endif

#include <thrift/transport/PlatformSocket.h>

Expand Down Expand Up @@ -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()};
Expand Down

0 comments on commit c31244d

Please sign in to comment.