Fail build on warnings in the native transport
Motivation: We should fail the build on warnings in the JNI/c code. Modifications: - Add GCC flag to fail build on warnings. - Fix warnings (which also fixed a bug when using splice with offsets). Result: Better code quality.
This commit is contained in:
parent
696a287736
commit
f3184f56c8
@ -186,7 +186,7 @@
|
|||||||
<value>${linux.sendmmsg.support}${glibc.sendmmsg.support}</value>
|
<value>${linux.sendmmsg.support}${glibc.sendmmsg.support}</value>
|
||||||
<!-- If glibc and linux kernel are both not sufficient...then define the CFLAGS -->
|
<!-- If glibc and linux kernel are both not sufficient...then define the CFLAGS -->
|
||||||
<regex>.*IO_NETTY_SENDMSSG_NOT_FOUND.*</regex>
|
<regex>.*IO_NETTY_SENDMSSG_NOT_FOUND.*</regex>
|
||||||
<replacement>CFLAGS=-O3 -DIO_NETTY_SENDMMSG_NOT_FOUND</replacement>
|
<replacement>CFLAGS=-O3 -DIO_NETTY_SENDMMSG_NOT_FOUND -Werror</replacement>
|
||||||
<failIfNoMatch>false</failIfNoMatch>
|
<failIfNoMatch>false</failIfNoMatch>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -202,7 +202,7 @@
|
|||||||
<value>${jni.compiler.args}</value>
|
<value>${jni.compiler.args}</value>
|
||||||
<!-- If glibc and linux kernel are both not sufficient...then define the CFLAGS -->
|
<!-- If glibc and linux kernel are both not sufficient...then define the CFLAGS -->
|
||||||
<regex>^((?!CFLAGS=).)*$</regex>
|
<regex>^((?!CFLAGS=).)*$</regex>
|
||||||
<replacement>CFLAGS=-O3</replacement>
|
<replacement>CFLAGS=-O3 -Werror</replacement>
|
||||||
<failIfNoMatch>false</failIfNoMatch>
|
<failIfNoMatch>false</failIfNoMatch>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include "io_netty_channel_epoll_Native.h"
|
#include "io_netty_channel_epoll_Native.h"
|
||||||
#include "exception_helper.h"
|
#include "exception_helper.h"
|
||||||
|
|
||||||
@ -1057,6 +1058,8 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_shutdown0(JNIEnv* env,
|
|||||||
mode = SHUT_RD;
|
mode = SHUT_RD;
|
||||||
} else if (write) {
|
} else if (write) {
|
||||||
mode = SHUT_WR;
|
mode = SHUT_WR;
|
||||||
|
} else {
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (shutdown(fd, mode) < 0) {
|
if (shutdown(fd, mode) < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
@ -1097,12 +1100,14 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_bind(JNIEnv* env, jcla
|
|||||||
if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
|
if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_listen0(JNIEnv* env, jclass clazz, jint fd, jint backlog) {
|
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_listen0(JNIEnv* env, jclass clazz, jint fd, jint backlog) {
|
||||||
if (listen(fd, backlog) == -1) {
|
if (listen(fd, backlog) == -1) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_connect(JNIEnv* env, jclass clazz, jint fd, jbyteArray address, jint scopeId, jint port) {
|
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_connect(JNIEnv* env, jclass clazz, jint fd, jbyteArray address, jint scopeId, jint port) {
|
||||||
@ -1560,7 +1565,7 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_socketDomain(JNIEnv* e
|
|||||||
|
|
||||||
// macro to calculate the length of a sockaddr_un struct for a given path length.
|
// macro to calculate the length of a sockaddr_un struct for a given path length.
|
||||||
// see sys/un.h#SUN_LEN, this is modified to allow nul bytes
|
// see sys/un.h#SUN_LEN, this is modified to allow nul bytes
|
||||||
#define _UNIX_ADDR_LENGTH(path_len) (((struct sockaddr_un *) 0)->sun_path) + path_len
|
#define _UNIX_ADDR_LENGTH(path_len) (uintptr_t) (((struct sockaddr_un *) 0)->sun_path) + path_len
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_bindDomainSocket(JNIEnv* env, jclass clazz, jint fd, jbyteArray socketPath) {
|
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_bindDomainSocket(JNIEnv* env, jclass clazz, jint fd, jbyteArray socketPath) {
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
@ -1568,7 +1573,7 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_bindDomainSocket(JNIEn
|
|||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
const jbyte* socket_path = (*env)->GetByteArrayElements(env, socketPath, 0);
|
jbyte* socket_path = (*env)->GetByteArrayElements(env, socketPath, 0);
|
||||||
jint socket_path_len = (*env)->GetArrayLength(env, socketPath);
|
jint socket_path_len = (*env)->GetArrayLength(env, socketPath);
|
||||||
if (socket_path_len > sizeof(addr.sun_path)) {
|
if (socket_path_len > sizeof(addr.sun_path)) {
|
||||||
socket_path_len = sizeof(addr.sun_path);
|
socket_path_len = sizeof(addr.sun_path);
|
||||||
@ -1595,7 +1600,7 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_connectDomainSocket(JN
|
|||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
const jbyte* socket_path = (*env)->GetByteArrayElements(env, socketPath, 0);
|
jbyte* socket_path = (*env)->GetByteArrayElements(env, socketPath, 0);
|
||||||
socket_path_len = (*env)->GetArrayLength(env, socketPath);
|
socket_path_len = (*env)->GetArrayLength(env, socketPath);
|
||||||
if (socket_path_len > sizeof(addr.sun_path)) {
|
if (socket_path_len > sizeof(addr.sun_path)) {
|
||||||
socket_path_len = sizeof(addr.sun_path);
|
socket_path_len = sizeof(addr.sun_path);
|
||||||
@ -1685,7 +1690,7 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_sendFd0(JNIEnv* env, j
|
|||||||
iov[0].iov_base = iovecData;
|
iov[0].iov_base = iovecData;
|
||||||
iov[0].iov_len = sizeof(iovecData);
|
iov[0].iov_len = sizeof(iovecData);
|
||||||
|
|
||||||
size_t res;
|
ssize_t res;
|
||||||
int err;
|
int err;
|
||||||
do {
|
do {
|
||||||
res = sendmsg(socketFd, &descriptorMessage, 0);
|
res = sendmsg(socketFd, &descriptorMessage, 0);
|
||||||
@ -1758,14 +1763,17 @@ JNIEXPORT jlong JNICALL Java_io_netty_channel_epoll_Native_pipe0(JNIEnv* env, jc
|
|||||||
return (((long) fd[0]) << 32) | (fd[1] & 0xffffffffL);
|
return (((long) fd[0]) << 32) | (fd[1] & 0xffffffffL);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_splice0(JNIEnv* env, jclass clazz, jint fd, jint offIn, jint fdOut, jint offOut, jint len) {
|
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_splice0(JNIEnv* env, jclass clazz, jint fd, jlong offIn, jint fdOut, jlong offOut, jlong len) {
|
||||||
ssize_t res;
|
ssize_t res;
|
||||||
int err;
|
int err;
|
||||||
loff_t off_in = offIn >= 0 ? (loff_t) offIn : NULL;
|
loff_t off_in = (loff_t) offIn;
|
||||||
loff_t off_out = offOut >= 0 ? (loff_t) offOut : NULL;
|
loff_t off_out = (loff_t) offOut;
|
||||||
|
|
||||||
|
loff_t* p_off_in = off_in >= 0 ? &off_in : NULL;
|
||||||
|
loff_t* p_off_out = off_in >= 0 ? &off_out : NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
res = splice(fd, off_in, fdOut, off_out, (size_t) len, SPLICE_F_NONBLOCK | SPLICE_F_MOVE);
|
res = splice(fd, p_off_in, fdOut, p_off_out, (size_t) len, SPLICE_F_NONBLOCK | SPLICE_F_MOVE);
|
||||||
// keep on splicing if it was interrupted
|
// keep on splicing if it was interrupted
|
||||||
} while (res == -1 && ((err = errno) == EINTR));
|
} while (res == -1 && ((err = errno) == EINTR));
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ jint Java_io_netty_channel_epoll_Native_sizeofEpollEvent(JNIEnv* env, jclass cla
|
|||||||
jint Java_io_netty_channel_epoll_Native_offsetofEpollData(JNIEnv* env, jclass clazz);
|
jint Java_io_netty_channel_epoll_Native_offsetofEpollData(JNIEnv* env, jclass clazz);
|
||||||
|
|
||||||
jlong Java_io_netty_channel_epoll_Native_pipe0(JNIEnv* env, jclass clazz);
|
jlong Java_io_netty_channel_epoll_Native_pipe0(JNIEnv* env, jclass clazz);
|
||||||
jint Java_io_netty_channel_epoll_Native_splice0(JNIEnv* env, jclass clazz, jint fd, jint offIn, jint fdOut, jint offOut, jint len);
|
jint Java_io_netty_channel_epoll_Native_splice0(JNIEnv* env, jclass clazz, jint fd, jlong offIn, jint fdOut, jlong offOut, jlong len);
|
||||||
|
|
||||||
jint Java_io_netty_channel_epoll_Native_tcpMd5SigMaxKeyLen(JNIEnv* env, jclass clazz);
|
jint Java_io_netty_channel_epoll_Native_tcpMd5SigMaxKeyLen(JNIEnv* env, jclass clazz);
|
||||||
void Java_io_netty_channel_epoll_Native_setTcpMd5Sig0(JNIEnv* env, jclass clazz, jint fd, jbyteArray address, jint scopeId, jbyteArray key);
|
void Java_io_netty_channel_epoll_Native_setTcpMd5Sig0(JNIEnv* env, jclass clazz, jint fd, jbyteArray address, jint scopeId, jbyteArray key);
|
||||||
|
@ -205,7 +205,7 @@ public final class Native {
|
|||||||
|
|
||||||
private static native int close0(int fd);
|
private static native int close0(int fd);
|
||||||
|
|
||||||
public static int splice(int fd, int offIn, int fdOut, int offOut, int len) throws IOException {
|
public static int splice(int fd, long offIn, int fdOut, long offOut, long len) throws IOException {
|
||||||
int res = splice0(fd, offIn, fdOut, offOut, len);
|
int res = splice0(fd, offIn, fdOut, offOut, len);
|
||||||
if (res >= 0) {
|
if (res >= 0) {
|
||||||
return res;
|
return res;
|
||||||
@ -213,7 +213,7 @@ public final class Native {
|
|||||||
return ioResult("splice", res, CONNECTION_RESET_EXCEPTION_SPLICE);
|
return ioResult("splice", res, CONNECTION_RESET_EXCEPTION_SPLICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native int splice0(int fd, int offIn, int fdOut, int offOut, int len);
|
private static native int splice0(int fd, long offIn, int fdOut, long offOut, long len);
|
||||||
|
|
||||||
public static long pipe() throws IOException {
|
public static long pipe() throws IOException {
|
||||||
long res = pipe0();
|
long res = pipe0();
|
||||||
|
Loading…
Reference in New Issue
Block a user