Move initAddress to LinuxSocket JNI

Motivation:

we should move the initAddress to LinuxSocket JNI as it is only used there

Modifications:

- cleanup
- move initAddress to linux socket JNI

Result:

it's cleaner
This commit is contained in:
Josef Grieb 2020-09-03 07:22:02 +02:00
parent 66ff2a2e23
commit 59f77c24b9
4 changed files with 19 additions and 41 deletions

View File

@ -102,6 +102,19 @@ static void netty_io_uring_linuxsocket_setInterface(JNIEnv* env, jclass clazz, j
}
}
static jint netty_io_uring_initAddress(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jbyteArray address, jint scopeId, jint port, jlong addressMemory) {
struct sockaddr_storage addr;
socklen_t addrSize;
if (netty_unix_socket_initSockaddr(env, ipv6, address, scopeId, port, &addr, &addrSize) == -1) {
// A runtime exception was thrown
return -1;
}
memcpy((void *) addressMemory, &addr, sizeof(struct sockaddr_storage));
return addrSize;
}
static void netty_io_uring_linuxsocket_setTcpCork(JNIEnv* env, jclass clazz, jint fd, jint optval) {
netty_unix_socket_setOption(env, fd, IPPROTO_TCP, TCP_CORK, &optval, sizeof(optval));
}
@ -700,7 +713,8 @@ static const JNINativeMethod fixed_method_table[] = {
{ "joinGroup", "(IZ[B[BII)V", (void *) netty_io_uring_linuxsocket_joinGroup },
{ "joinSsmGroup", "(IZ[B[BII[B)V", (void *) netty_io_uring_linuxsocket_joinSsmGroup },
{ "leaveGroup", "(IZ[B[BII)V", (void *) netty_io_uring_linuxsocket_leaveGroup },
{ "leaveSsmGroup", "(IZ[B[BII[B)V", (void *) netty_io_uring_linuxsocket_leaveSsmGroup }
{ "leaveSsmGroup", "(IZ[B[BII[B)V", (void *) netty_io_uring_linuxsocket_leaveSsmGroup },
{"initAddress", "(IZ[BIIJ)I", (void *) netty_io_uring_initAddress }
// "sendFile" has a dynamic signature
};

View File

@ -212,40 +212,6 @@ static void netty_io_uring_eventFdRead(JNIEnv* env, jclass clazz, jint fd) {
}
}
static jint netty_io_uring_initAddress(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jbyteArray address, jint scopeId, jint port, jlong remoteMemoryAddress) {
struct sockaddr_storage addr;
socklen_t addrSize;
if (netty_unix_socket_initSockaddr(env, ipv6, address, scopeId, port, &addr, &addrSize) == -1) {
// A runtime exception was thrown
return -1;
}
memcpy((void *) remoteMemoryAddress, &addr, sizeof(struct sockaddr_storage));
return addrSize;
}
//static jint netty_unix_socket_connect(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jbyteArray address, jint scopeId, jint port) {
// struct sockaddr_storage addr;
// socklen_t addrSize;
// if (netty_unix_socket_initSockaddr(env, ipv6, address, scopeId, port, &addr, &addrSize) == -1) {
// // A runtime exception was thrown
// return -1;
// }
//
// int res;
// int err;
// do {
// res = connect(fd, (struct sockaddr*) &addr, addrSize);
// } while (res == -1 && ((err = errno) == EINTR));
//
// if (res < 0) {
// return -err;
// }
// return 0;
//}
static void netty_io_uring_eventFdWrite(JNIEnv* env, jclass clazz, jint fd, jlong value) {
uint64_t val;
@ -442,8 +408,7 @@ static const JNINativeMethod method_table[] = {
{"eventFdWrite", "(IJ)V", (void *) netty_io_uring_eventFdWrite },
{"eventFdRead", "(I)V", (void *) netty_io_uring_eventFdRead },
{"ioUringRegisterEventFd", "(II)I", (void *) netty_io_uring_register_event_fd},
{"ioUringUnregisterEventFd", "(I)I", (void *) netty_io_uring_unregister_event_fd},
{"initAddress", "(IZ[BIIJ)I", (void *) netty_io_uring_initAddress }
{"ioUringUnregisterEventFd", "(I)I", (void *) netty_io_uring_unregister_event_fd}
};
static const jint method_table_size =
sizeof(method_table) / sizeof(method_table[0]);

View File

@ -67,8 +67,8 @@ final class LinuxSocket extends Socket {
setInterface(intValue(), ipv6, nativeAddress.address(), nativeAddress.scopeId(), interfaceIndex(netInterface));
}
public int initAddress(byte[] address, int scopeId, int port, long remoteAddressMemoryAddress) {
return Native.initAddress(intValue(), ipv6, address, scopeId, port, remoteAddressMemoryAddress);
public int initAddress(byte[] address, int scopeId, int port, long addressMemory) {
return initAddress(intValue(), ipv6, address, scopeId, port, addressMemory);
}
InetAddress getInterface() throws IOException {
@ -387,4 +387,5 @@ final class LinuxSocket extends Socket {
private static native int getIpMulticastLoop(int fd, boolean ipv6) throws IOException;
private static native void setIpMulticastLoop(int fd, boolean ipv6, int enabled) throws IOException;
private static native void setTimeToLive(int fd, int ttl) throws IOException;
private static native int initAddress(int fd, boolean ipv6, byte[] address, int scopeId, int port, long memoryAddress);
}

View File

@ -105,8 +105,6 @@ final class Native {
public static native void ioUringExit(RingBuffer ringBuffer);
public static native int initAddress(int fd, boolean ipv6, byte[] address, int scopeId, int port, long remoteMemoryAddress);
private static native int eventFd();
// for testing(it is only temporary)