Cleanup
Motivation: fix checkstyle errors and many classes are unnecessarily public Modification: -fixed maven checkstyle errors -using package-private and final classes Result: better code quality
This commit is contained in:
parent
8c9b874a2d
commit
eb1c8e4991
@ -43,7 +43,6 @@
|
||||
<artifactId>netty-buffer</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-transport-native-io_uring</artifactId>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash -e
|
||||
EXAMPLE_MAP=(
|
||||
'uring:io.netty.example.uring.EchoIOUringServer'
|
||||
'io_uring:io.netty.example.uring.EchoIOUringServer'
|
||||
'discard-client:io.netty.example.discard.DiscardClient'
|
||||
'discard-server:io.netty.example.discard.DiscardServer'
|
||||
'echo-client:io.netty.example.echo.EchoClient'
|
||||
|
@ -17,13 +17,16 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "netty_unix_buffer.h"
|
||||
#include "netty_unix_errors.h"
|
||||
#include "netty_unix_filedescriptor.h"
|
||||
#include "netty_unix_jni.h"
|
||||
#include "netty_unix_limits.h"
|
||||
#include "netty_unix_socket.h"
|
||||
#include "netty_unix_util.h"
|
||||
#ifndef LIB_TEST
|
||||
#define LIB_TEST
|
||||
|
||||
#ifndef NETTY_IO_URING
|
||||
#define NETTY_IO_URING
|
||||
|
||||
struct io_uring_sq {
|
||||
unsigned *khead;
|
||||
|
@ -56,14 +56,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "netty_unix_buffer.h"
|
||||
#include "netty_unix_errors.h"
|
||||
#include "netty_unix_filedescriptor.h"
|
||||
#include "netty_unix_jni.h"
|
||||
#include "netty_unix_limits.h"
|
||||
#include "netty_unix_socket.h"
|
||||
#include "netty_unix_util.h"
|
||||
|
||||
static jmethodID ringBufferMethodId = NULL;
|
||||
static jmethodID ioUringSubmissionQueueMethodId = NULL;
|
||||
static jmethodID ioUringCommpletionQueueMethodId = NULL;
|
||||
@ -73,12 +65,14 @@ static jclass ioUringSubmissionQueueClass = NULL;
|
||||
|
||||
void io_uring_unmap_rings(struct io_uring_sq *sq, struct io_uring_cq *cq) {
|
||||
munmap(sq->ring_ptr, sq->ring_sz);
|
||||
if (cq->ring_ptr && cq->ring_ptr != sq->ring_ptr)
|
||||
if (cq->ring_ptr && cq->ring_ptr != sq->ring_ptr) {
|
||||
munmap(cq->ring_ptr, cq->ring_sz);
|
||||
}
|
||||
}
|
||||
|
||||
int io_uring_mmap(int fd, struct io_uring_params *p, struct io_uring_sq *sq,
|
||||
struct io_uring_cq *cq) {
|
||||
static int io_uring_mmap(int fd, struct io_uring_params *p,
|
||||
struct io_uring_sq *sq, struct io_uring_cq *cq)
|
||||
{
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
@ -116,13 +110,12 @@ int io_uring_mmap(int fd, struct io_uring_params *p, struct io_uring_sq *sq,
|
||||
sq->array = sq->ring_ptr + p->sq_off.array;
|
||||
|
||||
size = p->sq_entries * sizeof(struct io_uring_sqe);
|
||||
sq->sqes = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE,
|
||||
fd, IORING_OFF_SQES);
|
||||
sq->sqes = mmap(0, size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_POPULATE, fd,
|
||||
IORING_OFF_SQES);
|
||||
if (sq->sqes == MAP_FAILED) {
|
||||
ret = -errno;
|
||||
err:
|
||||
io_uring_unmap_rings(sq, cq);
|
||||
return ret;
|
||||
goto err;
|
||||
}
|
||||
|
||||
cq->khead = cq->ring_ptr + p->cq_off.head;
|
||||
@ -131,7 +124,11 @@ int io_uring_mmap(int fd, struct io_uring_params *p, struct io_uring_sq *sq,
|
||||
cq->kring_entries = cq->ring_ptr + p->cq_off.ring_entries;
|
||||
cq->koverflow = cq->ring_ptr + p->cq_off.overflow;
|
||||
cq->cqes = cq->ring_ptr + p->cq_off.cqes;
|
||||
|
||||
return 0;
|
||||
err:
|
||||
io_uring_unmap_rings(sq, cq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void setup_io_uring(int ring_fd, struct io_uring *io_uring_ring,
|
||||
@ -143,6 +140,7 @@ void setup_io_uring(int ring_fd, struct io_uring *io_uring_ring,
|
||||
io_uring_ring->flags = p->flags;
|
||||
io_uring_ring->ring_fd = ring_fd;
|
||||
} else {
|
||||
//Todo signal this back to EventLoop
|
||||
perror("setup_io_uring error \n");
|
||||
}
|
||||
}
|
||||
@ -152,6 +150,10 @@ static jint netty_io_uring_enter(JNIEnv *env, jclass class1, jint ring_fd, jint
|
||||
return sys_io_uring_enter(ring_fd, to_submit, min_complete, flags, NULL);
|
||||
}
|
||||
|
||||
static int nettyBlockingSocket(int domain, int type, int protocol) {
|
||||
return socket(domain, type, protocol);
|
||||
}
|
||||
|
||||
static jobject netty_io_uring_setup(JNIEnv *env, jclass class1, jint entries) {
|
||||
struct io_uring_params p;
|
||||
memset(&p, 0, sizeof(p));
|
||||
@ -163,15 +165,13 @@ static jobject netty_io_uring_setup(JNIEnv *env, jclass class1, jint entries) {
|
||||
//throw Exception
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct io_uring io_uring_ring;
|
||||
//memset instead
|
||||
//Todo memset instead
|
||||
io_uring_ring.flags = 0;
|
||||
io_uring_ring.sq.sqe_tail = 0;
|
||||
io_uring_ring.sq.sqe_head = 0;
|
||||
setup_io_uring(ring_fd, &io_uring_ring, &p);
|
||||
|
||||
|
||||
jobject ioUringSubmissionQueue = (*env)->NewObject(
|
||||
env, ioUringSubmissionQueueClass, ioUringSubmissionQueueMethodId,
|
||||
(jlong)io_uring_ring.sq.khead, (jlong)io_uring_ring.sq.ktail,
|
||||
@ -197,19 +197,18 @@ static jobject netty_io_uring_setup(JNIEnv *env, jclass class1, jint entries) {
|
||||
return ringBuffer;
|
||||
}
|
||||
|
||||
static jlong netty_create_file(JNIEnv *env, jclass class) {
|
||||
static jint netty_create_file(JNIEnv *env, jclass class) {
|
||||
return open("io-uring-test.txt", O_RDWR | O_TRUNC | O_CREAT, 0644);
|
||||
}
|
||||
|
||||
static void netty_io_uring_native_JNI_OnUnLoad(JNIEnv *env) {
|
||||
// OnUnLoad
|
||||
// Todo OnUnLoad
|
||||
}
|
||||
|
||||
// JNI Method Registration Table Begin
|
||||
static const JNINativeMethod method_table[] = {
|
||||
{"ioUringSetup", "(I)Lio/netty/channel/uring/RingBuffer;",
|
||||
(void *)netty_io_uring_setup},
|
||||
{"createFile", "()J", (void *)netty_create_file},
|
||||
{"ioUringSetup", "(I)Lio/netty/channel/uring/RingBuffer;", (void *)netty_io_uring_setup},
|
||||
{"createFile", "()I", (void *)netty_create_file},
|
||||
{"ioUringEnter", "(IIII)I", (void *)netty_io_uring_enter}};
|
||||
static const jint method_table_size =
|
||||
sizeof(method_table) / sizeof(method_table[0]);
|
||||
@ -291,7 +290,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
ioUringCommpletionQueueMethodId, "<init>", "(JJJJJJIJI)V",
|
||||
done);
|
||||
|
||||
done:
|
||||
done:
|
||||
//unload
|
||||
|
||||
return NETTY_JNI_VERSION;
|
||||
|
@ -19,11 +19,6 @@
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int sys_io_uring_register(int fd, unsigned opcode, const void *arg,
|
||||
unsigned nr_args) {
|
||||
return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);
|
||||
}
|
||||
|
||||
int sys_io_uring_setup(unsigned entries, struct io_uring_params *p) {
|
||||
return syscall(__NR_io_uring_setup, entries, p);
|
||||
}
|
||||
|
@ -24,7 +24,5 @@
|
||||
extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p);
|
||||
extern int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
|
||||
unsigned flags, sigset_t *sig);
|
||||
extern int sys_io_uring_register(int fd, unsigned int opcode, const void *arg,
|
||||
unsigned int nr_args);
|
||||
|
||||
#endif
|
@ -151,7 +151,7 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
|
||||
|
||||
// Channel/ChannelHandlerContext.read() was called
|
||||
@Override
|
||||
protected void doBeginRead() throws Exception {
|
||||
protected void doBeginRead() {
|
||||
final AbstractUringUnsafe unsafe = (AbstractUringUnsafe) unsafe();
|
||||
if (!uringInReadyPending) {
|
||||
uringInReadyPending = true;
|
||||
|
@ -17,7 +17,7 @@ package io.netty.channel.uring;
|
||||
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
public class IOUringCompletionQueue {
|
||||
final class IOUringCompletionQueue {
|
||||
|
||||
//these offsets are used to access specific properties
|
||||
//CQE (https://github.com/axboe/liburing/blob/master/src/include/liburing/io_uring.h#L162)
|
||||
@ -42,7 +42,7 @@ public class IOUringCompletionQueue {
|
||||
private final long ringAddress;
|
||||
private final int ringFd;
|
||||
|
||||
public IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kringMaskAddress, long kringEntries,
|
||||
IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kringMaskAddress, long kringEntries,
|
||||
long kOverflowAddress, long completionQueueArrayAddress, int ringSize, long ringAddress, int ringFd) {
|
||||
this.kHeadAddress = kHeadAddress;
|
||||
this.kTailAddress = kTailAddress;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.channel.uring;
|
||||
|
||||
class IOUringCqe {
|
||||
final class IOUringCqe {
|
||||
private final long eventId;
|
||||
private final int res;
|
||||
private final long flags;
|
||||
|
@ -25,14 +25,14 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import static io.netty.channel.unix.Errors.*;
|
||||
|
||||
class IOUringEventLoop extends SingleThreadEventLoop {
|
||||
final class IOUringEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
// events should be unique to identify which event type that was
|
||||
private long eventIdCounter;
|
||||
private final LongObjectHashMap<Event> events = new LongObjectHashMap<Event>();
|
||||
private RingBuffer ringBuffer;
|
||||
|
||||
protected IOUringEventLoop(final EventLoopGroup parent, final Executor executor, final boolean addTaskWakesUp) {
|
||||
IOUringEventLoop(final EventLoopGroup parent, final Executor executor, final boolean addTaskWakesUp) {
|
||||
super(parent, executor, addTaskWakesUp);
|
||||
ringBuffer = Native.createRingBuffer(32);
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import static io.netty.util.internal.ObjectUtil.*;
|
||||
|
||||
public class IOUringServerChannelConfig extends IOUringChannelConfig implements ServerSocketChannelConfig {
|
||||
private volatile int backlog = NetUtil.SOMAXCONN;
|
||||
private volatile int pendingFastOpenRequestsThreshold;
|
||||
|
||||
IOUringServerChannelConfig(AbstractIOUringServerChannel channel) {
|
||||
super(channel);
|
||||
|
@ -23,7 +23,7 @@ import io.netty.channel.unix.Socket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class IOUringServerSocketChannel extends AbstractIOUringServerChannel implements ServerSocketChannel {
|
||||
public final class IOUringServerSocketChannel extends AbstractIOUringServerChannel implements ServerSocketChannel {
|
||||
private final IOUringServerSocketChannelConfig config;
|
||||
|
||||
public IOUringServerSocketChannel() {
|
||||
|
@ -32,7 +32,7 @@ import io.netty.channel.unix.FileDescriptor;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class IOUringSocketChannel extends AbstractIOUringChannel implements SocketChannel {
|
||||
public final class IOUringSocketChannel extends AbstractIOUringChannel implements SocketChannel {
|
||||
private final IOUringSocketChannelConfig config;
|
||||
|
||||
IOUringSocketChannel(final Channel parent, final LinuxSocket fd) {
|
||||
|
@ -17,7 +17,7 @@ package io.netty.channel.uring;
|
||||
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
public class IOUringSubmissionQueue {
|
||||
final class IOUringSubmissionQueue {
|
||||
|
||||
private static final int SQE_SIZE = 64;
|
||||
private static final int INT_SIZE = Integer.BYTES; //no 32 Bit support?
|
||||
@ -53,7 +53,7 @@ public class IOUringSubmissionQueue {
|
||||
private final long ringAddress;
|
||||
private final int ringFd;
|
||||
|
||||
public IOUringSubmissionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress,
|
||||
IOUringSubmissionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress,
|
||||
long fFlagsAdress, long kDroppedAddress, long arrayAddress,
|
||||
long submissionQueueArrayAddress, int ringSize,
|
||||
long ringAddress, int ringFd) {
|
||||
|
@ -17,10 +17,10 @@ package io.netty.channel.uring;
|
||||
|
||||
import io.netty.channel.unix.Socket;
|
||||
|
||||
public class LinuxSocket extends Socket {
|
||||
final class LinuxSocket extends Socket {
|
||||
private final int fd;
|
||||
|
||||
public LinuxSocket(final int fd) {
|
||||
LinuxSocket(final int fd) {
|
||||
super(fd);
|
||||
this.fd = fd;
|
||||
}
|
||||
|
@ -15,19 +15,14 @@
|
||||
*/
|
||||
package io.netty.channel.uring;
|
||||
|
||||
import io.netty.channel.unix.FileDescriptor;
|
||||
import io.netty.channel.unix.Socket;
|
||||
import io.netty.util.internal.NativeLibraryLoader;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class Native {
|
||||
final class Native {
|
||||
|
||||
private static final int DEFAULT_RING_SIZE = SystemPropertyUtil.getInt("io.netty.uring.ringSize", 32);
|
||||
static {
|
||||
@ -50,7 +45,7 @@ public final class Native {
|
||||
public static native int ioUringEnter(int ringFd, int toSubmit, int minComplete, int flags);
|
||||
|
||||
// for testing(it is only temporary)
|
||||
public static native long createFile();
|
||||
public static native int createFile();
|
||||
|
||||
private Native() {
|
||||
// utility
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.channel.uring;
|
||||
|
||||
|
||||
class RingBuffer {
|
||||
final class RingBuffer {
|
||||
private final IOUringSubmissionQueue ioUringSubmissionQueue;
|
||||
private final IOUringCompletionQueue ioUringCompletionQueue;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
/**
|
||||
* io_uring
|
||||
* io_uring is a high I/O performance scalable interface for fully
|
||||
* asynchronous Linux syscalls <a href="https://kernel.dk/io_uring.pdf">io_uring doc</a>
|
||||
*/
|
||||
package io.netty.channel.uring;
|
||||
|
@ -15,16 +15,10 @@
|
||||
*/
|
||||
package io.netty.channel.uring;
|
||||
|
||||
import io.netty.channel.unix.Socket;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import io.netty.buffer.UnpooledUnsafeDirectByteBuf;
|
||||
import static org.junit.Assert.*;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@ -37,8 +31,7 @@ public class NativeTest {
|
||||
ByteBufAllocator allocator = new UnpooledByteBufAllocator(true);
|
||||
ByteBuf writeEventByteBuf = allocator.directBuffer(100);
|
||||
String inputString = "Hello World!";
|
||||
byte[] byteArrray = inputString.getBytes();
|
||||
writeEventByteBuf.writeBytes(byteArrray);
|
||||
writeEventByteBuf.writeCharSequence(inputString, Charset.forName("UTF-8"));
|
||||
|
||||
int fd = (int) Native.createFile();
|
||||
|
||||
@ -73,7 +66,7 @@ public class NativeTest {
|
||||
byte[] dataRead = new byte[inputString.length()];
|
||||
readEventByteBuf.readBytes(dataRead);
|
||||
|
||||
assertEquals(inputString, new String(dataRead));
|
||||
assertArrayEquals(inputString.getBytes(), dataRead);
|
||||
readEventByteBuf.release();
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,7 @@ public class FileDescriptor {
|
||||
}
|
||||
|
||||
static boolean isClosed(int state) {
|
||||
System.out.println("State: " + state);
|
||||
return (state & STATE_CLOSED_MASK) != 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user