Skip to content

Commit f021217

Browse files
committed
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: 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 <[email protected]>
1 parent ba01a8c commit f021217

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed

lib/cpp/src/thrift/Thrift.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
#include <sys/types.h>
3131
#ifdef HAVE_NETINET_IN_H
32+
#ifdef __ZEPHYR__
33+
#include <zephyr/posix/netinet/in.h>
34+
#else
3235
#include <netinet/in.h>
3336
#endif
37+
#endif
3438
#ifdef HAVE_INTTYPES_H
3539
#include <inttypes.h>
3640
#endif

lib/cpp/src/thrift/protocol/TProtocol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
#include <memory>
3636

3737
#ifdef HAVE_NETINET_IN_H
38+
#ifdef __ZEPHYR__
39+
#include <zephyr/posix/netinet/in.h>
40+
#else
3841
#include <netinet/in.h>
3942
#endif
43+
#endif
4044
#include <sys/types.h>
4145
#include <string>
4246
#include <map>

lib/cpp/src/thrift/transport/PlatformSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
# define THRIFT_LSEEK lseek
108108
# define THRIFT_WRITE write
109109
# define THRIFT_READ read
110+
int ioctl(int fd, unsigned long request, ...);
110111
# define THRIFT_IOCTL_SOCKET ioctl
111112
# define THRIFT_IOCTL_SOCKET_NUM_BYTES_TYPE int
112113
# define THRIFT_STAT stat

lib/cpp/src/thrift/transport/SocketCommon.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@
2525
#include <thrift/thrift-config.h>
2626

2727
#ifdef HAVE_UNISTD_H
28+
#ifdef __ZEPHYR__
29+
#include <zephyr/posix/unistd.h>
30+
#else
2831
#include <unistd.h>
2932
#endif
33+
#endif
3034
#ifdef HAVE_SYS_UN_H
3135
#include <sys/un.h>
3236
#endif
3337
#ifdef HAVE_AF_UNIX_H
3438
#include <afunix.h>
3539
#endif
3640
#ifdef HAVE_SYS_SOCKET_H
41+
#ifdef __ZEPHYR__
42+
#include <zephyr/posix/sys/socket.h>
43+
#else
3744
#include <sys/socket.h>
3845
#endif
46+
#endif
3947

4048
#include <string>
4149

lib/cpp/src/thrift/transport/TServerSocket.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,42 @@
2424
#include <stdexcept>
2525
#include <sys/types.h>
2626
#ifdef HAVE_SYS_SOCKET_H
27+
#ifdef __ZEPHYR__
28+
#include <zephyr/posix/sys/socket.h>
29+
#else
2730
#include <sys/socket.h>
2831
#endif
32+
#endif
2933
#ifdef HAVE_SYS_UN_H
3034
#include <sys/un.h>
3135
#endif
3236
#ifdef HAVE_SYS_POLL_H
3337
#include <sys/poll.h>
3438
#endif
3539
#ifdef HAVE_NETINET_IN_H
40+
#ifdef __ZEPHYR__
41+
#include <zephyr/posix/netinet/in.h>
42+
#include <zephyr/posix/netinet/tcp.h>
43+
#else
3644
#include <netinet/in.h>
3745
#include <netinet/tcp.h>
3846
#endif
47+
#endif
3948
#ifdef HAVE_NETDB_H
49+
#ifdef __ZEPHYR__
50+
#include <zephyr/posix/netdb.h>
51+
#else
4052
#include <netdb.h>
4153
#endif
54+
#endif
4255
#include <fcntl.h>
4356
#ifdef HAVE_UNISTD_H
57+
#ifdef __ZEPHYR__
58+
#include <zephyr/posix/unistd.h>
59+
#else
4460
#include <unistd.h>
4561
#endif
62+
#endif
4663
#ifdef HAVE_SYS_STAT_H
4764
#include <sys/stat.h>
4865
#endif

lib/cpp/src/thrift/transport/TServerSocket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@
2828

2929
#include <sys/types.h>
3030
#ifdef HAVE_SYS_SOCKET_H
31+
#ifdef __ZEPHYR__
32+
#include <zephyr/posix/sys/socket.h>
33+
#else
3134
#include <sys/socket.h>
3235
#endif
36+
#endif
3337
#ifdef HAVE_NETDB_H
38+
#ifdef __ZEPHYR__
39+
#include <zephyr/posix/netdb.h>
40+
#else
3441
#include <netdb.h>
3542
#endif
43+
#endif
3644

3745
namespace apache {
3846
namespace thrift {

lib/cpp/src/thrift/transport/TSocket.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@
2222
#include <cstring>
2323
#include <sstream>
2424
#ifdef HAVE_SYS_IOCTL_H
25+
#ifdef __ZEPHYR__
26+
#include <errno.h>
27+
#include <zephyr/posix/sys/ioctl.h>
28+
__attribute__((weak))
29+
int ioctl(int fd, unsigned long request, ...)
30+
{
31+
(void)fd;
32+
(void)request;
33+
return -ENOSYS;
34+
}
35+
#else
2536
#include <sys/ioctl.h>
37+
#endif
2638
#ifdef __sun
2739
#include <sys/filio.h>
2840
#endif // __sun
2941
#endif
3042
#ifdef HAVE_SYS_SOCKET_H
43+
#ifdef __ZEPHYR__
44+
#include <zephyr/posix/sys/socket.h>
45+
#else
3146
#include <sys/socket.h>
3247
#endif
48+
#endif
3349
#ifdef HAVE_SYS_UN_H
3450
#include <sys/un.h>
3551
#endif
@@ -38,12 +54,21 @@
3854
#endif
3955
#include <sys/types.h>
4056
#ifdef HAVE_NETINET_IN_H
57+
#ifdef __ZEPHYR__
58+
#include <zephyr/posix/netinet/in.h>
59+
#include <zephyr/posix/netinet/tcp.h>
60+
#else
4161
#include <netinet/in.h>
4262
#include <netinet/tcp.h>
4363
#endif
64+
#endif
4465
#ifdef HAVE_UNISTD_H
66+
#ifdef __ZEPHYR__
67+
#include <zephyr/posix/unistd.h>
68+
#else
4569
#include <unistd.h>
4670
#endif
71+
#endif
4772
#include <fcntl.h>
4873

4974
#include <thrift/concurrency/Monitor.h>
@@ -457,8 +482,12 @@ void TSocket::local_open() {
457482
if (
458483
#ifdef _WIN32
459484
error == WSANO_DATA
485+
#else
486+
#ifdef __ZEPHYR__
487+
error == DNS_EAI_NODATA
460488
#else
461489
error == EAI_NODATA
490+
#endif
462491
#endif
463492
) {
464493
hints.ai_flags &= ~AI_ADDRCONFIG;

lib/cpp/src/thrift/transport/TSocket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@
2828
#include <thrift/transport/PlatformSocket.h>
2929

3030
#ifdef HAVE_ARPA_INET_H
31+
#ifdef __ZEPHYR__
32+
#include <zephyr/posix/arpa/inet.h>
33+
#else
3134
#include <arpa/inet.h>
3235
#endif
36+
#endif
3337
#ifdef HAVE_SYS_TIME_H
3438
#include <sys/time.h>
3539
#endif
3640
#ifdef HAVE_NETDB_H
41+
#ifdef __ZEPHYR__
42+
#include <zephyr/posix/netdb.h>
43+
#else
3744
#include <netdb.h>
3845
#endif
46+
#endif
3947

4048
namespace apache {
4149
namespace thrift {

lib/cpp/src/thrift/transport/TSocketUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@
2727

2828
#include <sys/types.h>
2929
#ifdef HAVE_SYS_SOCKET_H
30+
#ifdef __ZEPHYR__
31+
#include <zephyr/posix/sys/socket.h>
32+
#else
3033
#include <sys/socket.h>
3134
#endif
35+
#endif
3236
#ifdef HAVE_NETDB_H
37+
#ifdef __ZEPHYR__
38+
#include <zephyr/posix/netdb.h>
39+
#else
3340
#include <netdb.h>
3441
#endif
42+
#endif
3543

3644
#include <thrift/transport/PlatformSocket.h>
3745

@@ -111,8 +119,12 @@ struct AddressResolutionHelper {
111119
#ifdef _WIN32
112120
} else {
113121
throw std::system_error{THRIFT_GET_SOCKET_ERROR, std::system_category()};
122+
#else
123+
#ifdef __ZEPHYR__
124+
} else if (ret == DNS_EAI_SYSTEM) {
114125
#else
115126
} else if (ret == EAI_SYSTEM) {
127+
#endif
116128
throw std::system_error{THRIFT_GET_SOCKET_ERROR, std::system_category()};
117129
} else {
118130
throw std::system_error{ret, gai_error()};

0 commit comments

Comments
 (0)