Skip to content

Commit

Permalink
Fix C portability issues (#13947)
Browse files Browse the repository at this point in the history
Motivation:
Some GNU-isms had snuck into our Linux-specific C code, which meant we
required glibc to compile.

There is really not any reason to limit ourselves to that, though glibc
is obviously very popular, so is musl-libc.

Modification:
Use correct feature-test macros for defining `mmsghdr` on BSDs, and use
portable `unsigned char` and `unsigned int` instead of non-portable
`u_char` and `u_int`.

Result:
We can now compile on Linux distros that don't use glibc, such as
Alpine.
  • Loading branch information
chrisvest committed Apr 4, 2024
1 parent fee3c39 commit 801ae50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions transport-native-epoll/src/main/c/netty_epoll_linuxsocket.c
Expand Up @@ -163,10 +163,10 @@ static void netty_epoll_linuxsocket_setTimeToLive(JNIEnv* env, jclass clazz, jin

static void netty_epoll_linuxsocket_setIpMulticastLoop(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jint optval) {
if (ipv6 == JNI_TRUE) {
u_int val = (u_int) optval;
unsigned int val = (unsigned int) optval;
netty_unix_socket_setOption(env, fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val));
} else {
u_char val = (u_char) optval;
unsigned char val = (unsigned char) optval;
netty_unix_socket_setOption(env, fd, IPPROTO_IP, IP_MULTICAST_LOOP, &val, sizeof(val));
}
}
Expand Down Expand Up @@ -538,13 +538,13 @@ static jint netty_epoll_linuxsocket_getTimeToLive(JNIEnv* env, jclass clazz, jin

static jint netty_epoll_linuxsocket_getIpMulticastLoop(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6) {
if (ipv6 == JNI_TRUE) {
u_int optval;
unsigned int optval;
if (netty_unix_socket_getOption(env, fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &optval, sizeof(optval)) == -1) {
return -1;
}
return (jint) optval;
} else {
u_char optval;
unsigned char optval;
if (netty_unix_socket_getOption(env, fd, IPPROTO_IP, IP_MULTICAST_LOOP, &optval, sizeof(optval)) == -1) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion transport-native-epoll/src/main/c/netty_epoll_native.c
Expand Up @@ -86,7 +86,7 @@
extern int epoll_create1(int flags) __attribute__((weak));
extern int epoll_pwait2(int epfd, struct epoll_event *events, int maxevents, const struct timespec *timeout, const sigset_t *sigmask) __attribute__((weak));

#ifndef __USE_GNU
#ifndef _GNU_SOURCE
struct mmsghdr {
struct msghdr msg_hdr; /* Message header */
unsigned int msg_len; /* Number of bytes transmitted */
Expand Down

0 comments on commit 801ae50

Please sign in to comment.