diff --git a/transport-native-io_uring/src/main/c/netty_io_uring_linuxsocket.c b/transport-native-io_uring/src/main/c/netty_io_uring_linuxsocket.c index 9c82c2eb18..1f72894882 100644 --- a/transport-native-io_uring/src/main/c/netty_io_uring_linuxsocket.c +++ b/transport-native-io_uring/src/main/c/netty_io_uring_linuxsocket.c @@ -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 }; diff --git a/transport-native-io_uring/src/main/c/netty_io_uring_native.c b/transport-native-io_uring/src/main/c/netty_io_uring_native.c index 0b7ca9ddf2..4663493de9 100644 --- a/transport-native-io_uring/src/main/c/netty_io_uring_native.c +++ b/transport-native-io_uring/src/main/c/netty_io_uring_native.c @@ -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]); diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/LinuxSocket.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/LinuxSocket.java index 38504e2172..b618e94724 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/LinuxSocket.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/LinuxSocket.java @@ -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); } diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/Native.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/Native.java index e12c75c3e9..bee8f2bf18 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/Native.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/Native.java @@ -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)