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:
Josef Grieb 2020-07-22 14:01:48 +02:00
parent 8c9b874a2d
commit eb1c8e4991
20 changed files with 195 additions and 212 deletions

View File

@ -43,7 +43,6 @@
<artifactId>netty-buffer</artifactId> <artifactId>netty-buffer</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-io_uring</artifactId> <artifactId>netty-transport-native-io_uring</artifactId>

View File

@ -1,6 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
EXAMPLE_MAP=( EXAMPLE_MAP=(
'uring:io.netty.example.uring.EchoIOUringServer' 'io_uring:io.netty.example.uring.EchoIOUringServer'
'discard-client:io.netty.example.discard.DiscardClient' 'discard-client:io.netty.example.discard.DiscardClient'
'discard-server:io.netty.example.discard.DiscardServer' 'discard-server:io.netty.example.discard.DiscardServer'
'echo-client:io.netty.example.echo.EchoClient' 'echo-client:io.netty.example.echo.EchoClient'

View File

@ -17,48 +17,51 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "netty_unix_buffer.h"
#include "netty_unix_errors.h" #include "netty_unix_errors.h"
#include "netty_unix_filedescriptor.h" #include "netty_unix_filedescriptor.h"
#include "netty_unix_jni.h" #include "netty_unix_jni.h"
#include "netty_unix_limits.h"
#include "netty_unix_socket.h" #include "netty_unix_socket.h"
#include "netty_unix_util.h" #include "netty_unix_util.h"
#ifndef LIB_TEST
#define LIB_TEST #ifndef NETTY_IO_URING
#define NETTY_IO_URING
struct io_uring_sq { struct io_uring_sq {
unsigned *khead; unsigned *khead;
unsigned *ktail; unsigned *ktail;
unsigned *kring_mask; unsigned *kring_mask;
unsigned *kring_entries; unsigned *kring_entries;
unsigned *kflags; unsigned *kflags;
unsigned *kdropped; unsigned *kdropped;
unsigned *array; unsigned *array;
struct io_uring_sqe *sqes; struct io_uring_sqe *sqes;
unsigned sqe_head; unsigned sqe_head;
unsigned sqe_tail; unsigned sqe_tail;
size_t ring_sz; size_t ring_sz;
void *ring_ptr; void *ring_ptr;
}; };
struct io_uring_cq { struct io_uring_cq {
unsigned *khead; unsigned *khead;
unsigned *ktail; unsigned *ktail;
unsigned *kring_mask; unsigned *kring_mask;
unsigned *kring_entries; unsigned *kring_entries;
unsigned *koverflow; unsigned *koverflow;
struct io_uring_cqe *cqes; struct io_uring_cqe *cqes;
size_t ring_sz; size_t ring_sz;
void *ring_ptr; void *ring_ptr;
}; };
struct io_uring { struct io_uring {
struct io_uring_sq sq; struct io_uring_sq sq;
struct io_uring_cq cq; struct io_uring_cq cq;
unsigned flags; unsigned flags;
int ring_fd; int ring_fd;
}; };
#endif #endif

View File

@ -56,14 +56,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.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 ringBufferMethodId = NULL;
static jmethodID ioUringSubmissionQueueMethodId = NULL; static jmethodID ioUringSubmissionQueueMethodId = NULL;
static jmethodID ioUringCommpletionQueueMethodId = NULL; static jmethodID ioUringCommpletionQueueMethodId = NULL;
@ -72,183 +64,190 @@ static jclass ioUringCompletionQueueClass = NULL;
static jclass ioUringSubmissionQueueClass = NULL; static jclass ioUringSubmissionQueueClass = NULL;
void io_uring_unmap_rings(struct io_uring_sq *sq, struct io_uring_cq *cq) { void io_uring_unmap_rings(struct io_uring_sq *sq, struct io_uring_cq *cq) {
munmap(sq->ring_ptr, sq->ring_sz); 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); munmap(cq->ring_ptr, cq->ring_sz);
}
} }
int io_uring_mmap(int fd, struct io_uring_params *p, struct io_uring_sq *sq, static int io_uring_mmap(int fd, struct io_uring_params *p,
struct io_uring_cq *cq) { struct io_uring_sq *sq, struct io_uring_cq *cq)
size_t size; {
int ret; size_t size;
int ret;
sq->ring_sz = p->sq_off.array + p->sq_entries * sizeof(unsigned); sq->ring_sz = p->sq_off.array + p->sq_entries * sizeof(unsigned);
cq->ring_sz = p->cq_off.cqes + p->cq_entries * sizeof(struct io_uring_cqe); cq->ring_sz = p->cq_off.cqes + p->cq_entries * sizeof(struct io_uring_cqe);
if (p->features & IORING_FEAT_SINGLE_MMAP) { if (p->features & IORING_FEAT_SINGLE_MMAP) {
if (cq->ring_sz > sq->ring_sz) if (cq->ring_sz > sq->ring_sz)
sq->ring_sz = cq->ring_sz; sq->ring_sz = cq->ring_sz;
cq->ring_sz = sq->ring_sz; cq->ring_sz = sq->ring_sz;
} }
sq->ring_ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE, sq->ring_ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING); MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING);
if (sq->ring_ptr == MAP_FAILED) if (sq->ring_ptr == MAP_FAILED)
return -errno; return -errno;
if (p->features & IORING_FEAT_SINGLE_MMAP) { if (p->features & IORING_FEAT_SINGLE_MMAP) {
cq->ring_ptr = sq->ring_ptr; cq->ring_ptr = sq->ring_ptr;
} else { } else {
cq->ring_ptr = mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE, cq->ring_ptr = mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING); MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING);
if (cq->ring_ptr == MAP_FAILED) { if (cq->ring_ptr == MAP_FAILED) {
cq->ring_ptr = NULL; cq->ring_ptr = NULL;
ret = -errno; ret = -errno;
goto err; goto err;
} }
} }
sq->khead = sq->ring_ptr + p->sq_off.head; sq->khead = sq->ring_ptr + p->sq_off.head;
sq->ktail = sq->ring_ptr + p->sq_off.tail; sq->ktail = sq->ring_ptr + p->sq_off.tail;
sq->kring_mask = sq->ring_ptr + p->sq_off.ring_mask; sq->kring_mask = sq->ring_ptr + p->sq_off.ring_mask;
sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries; sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries;
sq->kflags = sq->ring_ptr + p->sq_off.flags; sq->kflags = sq->ring_ptr + p->sq_off.flags;
sq->kdropped = sq->ring_ptr + p->sq_off.dropped; sq->kdropped = sq->ring_ptr + p->sq_off.dropped;
sq->array = sq->ring_ptr + p->sq_off.array; sq->array = sq->ring_ptr + p->sq_off.array;
size = p->sq_entries * sizeof(struct io_uring_sqe); size = p->sq_entries * sizeof(struct io_uring_sqe);
sq->sqes = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, sq->sqes = mmap(0, size, PROT_READ | PROT_WRITE,
fd, IORING_OFF_SQES); MAP_SHARED | MAP_POPULATE, fd,
if (sq->sqes == MAP_FAILED) { IORING_OFF_SQES);
ret = -errno; if (sq->sqes == MAP_FAILED) {
err: ret = -errno;
io_uring_unmap_rings(sq, cq); goto err;
return ret; }
}
cq->khead = cq->ring_ptr + p->cq_off.head; cq->khead = cq->ring_ptr + p->cq_off.head;
cq->ktail = cq->ring_ptr + p->cq_off.tail; cq->ktail = cq->ring_ptr + p->cq_off.tail;
cq->kring_mask = cq->ring_ptr + p->cq_off.ring_mask; cq->kring_mask = cq->ring_ptr + p->cq_off.ring_mask;
cq->kring_entries = cq->ring_ptr + p->cq_off.ring_entries; cq->kring_entries = cq->ring_ptr + p->cq_off.ring_entries;
cq->koverflow = cq->ring_ptr + p->cq_off.overflow; cq->koverflow = cq->ring_ptr + p->cq_off.overflow;
cq->cqes = cq->ring_ptr + p->cq_off.cqes; cq->cqes = cq->ring_ptr + p->cq_off.cqes;
return 0;
return 0;
err:
io_uring_unmap_rings(sq, cq);
return ret;
} }
void setup_io_uring(int ring_fd, struct io_uring *io_uring_ring, void setup_io_uring(int ring_fd, struct io_uring *io_uring_ring,
struct io_uring_params *p) { struct io_uring_params *p) {
int ret; int ret;
ret = io_uring_mmap(ring_fd, p, &io_uring_ring->sq, &io_uring_ring->cq); ret = io_uring_mmap(ring_fd, p, &io_uring_ring->sq, &io_uring_ring->cq);
if (!ret) { if (!ret) {
io_uring_ring->flags = p->flags; io_uring_ring->flags = p->flags;
io_uring_ring->ring_fd = ring_fd; io_uring_ring->ring_fd = ring_fd;
} else { } else {
perror("setup_io_uring error \n"); //Todo signal this back to EventLoop
} perror("setup_io_uring error \n");
}
} }
static jint netty_io_uring_enter(JNIEnv *env, jclass class1, jint ring_fd, jint to_submit, static jint netty_io_uring_enter(JNIEnv *env, jclass class1, jint ring_fd, jint to_submit,
jint min_complete, jint flags) { jint min_complete, jint flags) {
return sys_io_uring_enter(ring_fd, to_submit, min_complete, flags, NULL); 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) { static jobject netty_io_uring_setup(JNIEnv *env, jclass class1, jint entries) {
struct io_uring_params p; struct io_uring_params p;
memset(&p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
int ring_fd = sys_io_uring_setup((int)entries, &p); int ring_fd = sys_io_uring_setup((int)entries, &p);
//Todo //Todo
if (ring_fd < -1) { if (ring_fd < -1) {
//throw Exception //throw Exception
return NULL; return NULL;
} }
struct io_uring io_uring_ring;
//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);
struct io_uring io_uring_ring; jobject ioUringSubmissionQueue = (*env)->NewObject(
//memset instead env, ioUringSubmissionQueueClass, ioUringSubmissionQueueMethodId,
io_uring_ring.flags = 0; (jlong)io_uring_ring.sq.khead, (jlong)io_uring_ring.sq.ktail,
io_uring_ring.sq.sqe_tail = 0; (jlong)io_uring_ring.sq.kring_mask,
io_uring_ring.sq.sqe_head = 0; (jlong)io_uring_ring.sq.kring_entries, (jlong)io_uring_ring.sq.kflags,
setup_io_uring(ring_fd, &io_uring_ring, &p); (jlong)io_uring_ring.sq.kdropped, (jlong)io_uring_ring.sq.array,
(jlong)io_uring_ring.sq.sqes, (jlong)io_uring_ring.sq.ring_sz,
(jlong)io_uring_ring.cq.ring_ptr, (jint)ring_fd);
jobject ioUringCompletionQueue = (*env)->NewObject(
env, ioUringCompletionQueueClass, ioUringCommpletionQueueMethodId,
(jlong)io_uring_ring.cq.khead, (jlong)io_uring_ring.cq.ktail,
(jlong)io_uring_ring.cq.kring_mask,
(jlong)io_uring_ring.cq.kring_entries,
(jlong)io_uring_ring.cq.koverflow, (jlong)io_uring_ring.cq.cqes,
(jlong)io_uring_ring.cq.ring_sz, (jlong)io_uring_ring.cq.ring_ptr,
(jint)ring_fd);
jobject ioUringSubmissionQueue = (*env)->NewObject( jobject ringBuffer =
env, ioUringSubmissionQueueClass, ioUringSubmissionQueueMethodId, (*env)->NewObject(env, ringBufferClass, ringBufferMethodId,
(jlong)io_uring_ring.sq.khead, (jlong)io_uring_ring.sq.ktail,
(jlong)io_uring_ring.sq.kring_mask,
(jlong)io_uring_ring.sq.kring_entries, (jlong)io_uring_ring.sq.kflags,
(jlong)io_uring_ring.sq.kdropped, (jlong)io_uring_ring.sq.array,
(jlong)io_uring_ring.sq.sqes, (jlong)io_uring_ring.sq.ring_sz,
(jlong)io_uring_ring.cq.ring_ptr, (jint)ring_fd);
jobject ioUringCompletionQueue = (*env)->NewObject(
env, ioUringCompletionQueueClass, ioUringCommpletionQueueMethodId,
(jlong)io_uring_ring.cq.khead, (jlong)io_uring_ring.cq.ktail,
(jlong)io_uring_ring.cq.kring_mask,
(jlong)io_uring_ring.cq.kring_entries,
(jlong)io_uring_ring.cq.koverflow, (jlong)io_uring_ring.cq.cqes,
(jlong)io_uring_ring.cq.ring_sz, (jlong)io_uring_ring.cq.ring_ptr,
(jint)ring_fd);
jobject ringBuffer =
(*env)->NewObject(env, ringBufferClass, ringBufferMethodId,
ioUringSubmissionQueue, ioUringCompletionQueue); ioUringSubmissionQueue, ioUringCompletionQueue);
return ringBuffer; 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); return open("io-uring-test.txt", O_RDWR | O_TRUNC | O_CREAT, 0644);
} }
static void netty_io_uring_native_JNI_OnUnLoad(JNIEnv *env) { static void netty_io_uring_native_JNI_OnUnLoad(JNIEnv *env) {
// OnUnLoad // Todo OnUnLoad
} }
// JNI Method Registration Table Begin // JNI Method Registration Table Begin
static const JNINativeMethod method_table[] = { static const JNINativeMethod method_table[] = {
{"ioUringSetup", "(I)Lio/netty/channel/uring/RingBuffer;", {"ioUringSetup", "(I)Lio/netty/channel/uring/RingBuffer;", (void *)netty_io_uring_setup},
(void *)netty_io_uring_setup}, {"createFile", "()I", (void *)netty_create_file},
{"createFile", "()J", (void *)netty_create_file},
{"ioUringEnter", "(IIII)I", (void *)netty_io_uring_enter}}; {"ioUringEnter", "(IIII)I", (void *)netty_io_uring_enter}};
static const jint method_table_size = static const jint method_table_size =
sizeof(method_table) / sizeof(method_table[0]); sizeof(method_table) / sizeof(method_table[0]);
// JNI Method Registration Table End // JNI Method Registration Table End
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env; JNIEnv *env;
char *nettyClassName = NULL; char *nettyClassName = NULL;
if ((*vm)->GetEnv(vm, (void **)&env, NETTY_JNI_VERSION) != JNI_OK) { if ((*vm)->GetEnv(vm, (void **)&env, NETTY_JNI_VERSION) != JNI_OK) {
return JNI_ERR; return JNI_ERR;
} }
char *packagePrefix = NULL; char *packagePrefix = NULL;
Dl_info dlinfo; Dl_info dlinfo;
jint status = 0; jint status = 0;
if (!dladdr((void *)netty_io_uring_native_JNI_OnUnLoad, &dlinfo)) { if (!dladdr((void *)netty_io_uring_native_JNI_OnUnLoad, &dlinfo)) {
fprintf(stderr, fprintf(stderr,
"FATAL: transport-native-epoll JNI call to dladdr failed!\n"); "FATAL: transport-native-epoll JNI call to dladdr failed!\n");
return JNI_ERR; return JNI_ERR;
} }
packagePrefix = netty_unix_util_parse_package_prefix( packagePrefix = netty_unix_util_parse_package_prefix(
dlinfo.dli_fname, "netty_transport_native_io_uring", &status); dlinfo.dli_fname, "netty_transport_native_io_uring", &status);
if (status == JNI_ERR) { if (status == JNI_ERR) {
fprintf(stderr, fprintf(stderr,
"FATAL: netty_transport_native_io_uring JNI encountered unexpected " "FATAL: netty_transport_native_io_uring JNI encountered unexpected "
"dlinfo.dli_fname: %s\n", "dlinfo.dli_fname: %s\n",
dlinfo.dli_fname); dlinfo.dli_fname);
return JNI_ERR; return JNI_ERR;
} }
if (netty_unix_util_register_natives(env, packagePrefix, if (netty_unix_util_register_natives(env, packagePrefix,
"io/netty/channel/uring/Native", "io/netty/channel/uring/Native",
method_table, method_table_size) != 0) { method_table, method_table_size) != 0) {
printf("netty register natives error\n"); printf("netty register natives error\n");
} }
// Load all c modules that we depend upon // Load all c modules that we depend upon
if (netty_unix_limits_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { if (netty_unix_limits_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done; goto done;
} }
@ -269,30 +268,30 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
goto done; goto done;
} }
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer", NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer",
nettyClassName, done); nettyClassName, done);
NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done); NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done);
NETTY_GET_METHOD(env, ringBufferClass, ringBufferMethodId, "<init>", NETTY_GET_METHOD(env, ringBufferClass, ringBufferMethodId, "<init>",
"(Lio/netty/channel/uring/IOUringSubmissionQueue;Lio/netty/" "(Lio/netty/channel/uring/IOUringSubmissionQueue;Lio/netty/"
"channel/uring/IOUringCompletionQueue;)V", "channel/uring/IOUringCompletionQueue;)V",
done); done);
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringSubmissionQueue", NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringSubmissionQueue",
nettyClassName, done); nettyClassName, done);
NETTY_LOAD_CLASS(env, ioUringSubmissionQueueClass, nettyClassName, done); NETTY_LOAD_CLASS(env, ioUringSubmissionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringSubmissionQueueClass, NETTY_GET_METHOD(env, ioUringSubmissionQueueClass,
ioUringSubmissionQueueMethodId, "<init>", "(JJJJJJJJIJI)V", ioUringSubmissionQueueMethodId, "<init>", "(JJJJJJJJIJI)V",
done); done);
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringCompletionQueue", NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringCompletionQueue",
nettyClassName, done); nettyClassName, done);
NETTY_LOAD_CLASS(env, ioUringCompletionQueueClass, nettyClassName, done); NETTY_LOAD_CLASS(env, ioUringCompletionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringCompletionQueueClass, NETTY_GET_METHOD(env, ioUringCompletionQueueClass,
ioUringCommpletionQueueMethodId, "<init>", "(JJJJJJIJI)V", ioUringCommpletionQueueMethodId, "<init>", "(JJJJJJIJI)V",
done); done);
done: done:
//unload //unload
return NETTY_JNI_VERSION; return NETTY_JNI_VERSION;
} }

View File

@ -19,17 +19,12 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <unistd.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) { int sys_io_uring_setup(unsigned entries, struct io_uring_params *p) {
return syscall(__NR_io_uring_setup, entries, p); return syscall(__NR_io_uring_setup, entries, p);
} }
int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete, int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
unsigned flags, sigset_t *sig) { unsigned flags, sigset_t *sig) {
return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, sig, return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, sig,
_NSIG / 8); _NSIG / 8);
} }

View File

@ -24,7 +24,5 @@
extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p); 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, extern int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
unsigned flags, sigset_t *sig); unsigned flags, sigset_t *sig);
extern int sys_io_uring_register(int fd, unsigned int opcode, const void *arg,
unsigned int nr_args);
#endif #endif

View File

@ -151,7 +151,7 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
// Channel/ChannelHandlerContext.read() was called // Channel/ChannelHandlerContext.read() was called
@Override @Override
protected void doBeginRead() throws Exception { protected void doBeginRead() {
final AbstractUringUnsafe unsafe = (AbstractUringUnsafe) unsafe(); final AbstractUringUnsafe unsafe = (AbstractUringUnsafe) unsafe();
if (!uringInReadyPending) { if (!uringInReadyPending) {
uringInReadyPending = true; uringInReadyPending = true;

View File

@ -17,7 +17,7 @@ package io.netty.channel.uring;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
public class IOUringCompletionQueue { final class IOUringCompletionQueue {
//these offsets are used to access specific properties //these offsets are used to access specific properties
//CQE (https://github.com/axboe/liburing/blob/master/src/include/liburing/io_uring.h#L162) //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 long ringAddress;
private final int ringFd; 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) { long kOverflowAddress, long completionQueueArrayAddress, int ringSize, long ringAddress, int ringFd) {
this.kHeadAddress = kHeadAddress; this.kHeadAddress = kHeadAddress;
this.kTailAddress = kTailAddress; this.kTailAddress = kTailAddress;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.channel.uring; package io.netty.channel.uring;
class IOUringCqe { final class IOUringCqe {
private final long eventId; private final long eventId;
private final int res; private final int res;
private final long flags; private final long flags;

View File

@ -25,14 +25,14 @@ import java.util.concurrent.Executor;
import static io.netty.channel.unix.Errors.*; 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 // events should be unique to identify which event type that was
private long eventIdCounter; private long eventIdCounter;
private final LongObjectHashMap<Event> events = new LongObjectHashMap<Event>(); private final LongObjectHashMap<Event> events = new LongObjectHashMap<Event>();
private RingBuffer ringBuffer; 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); super(parent, executor, addTaskWakesUp);
ringBuffer = Native.createRingBuffer(32); ringBuffer = Native.createRingBuffer(32);
} }

View File

@ -32,8 +32,7 @@ import static io.netty.channel.ChannelOption.*;
import static io.netty.util.internal.ObjectUtil.*; import static io.netty.util.internal.ObjectUtil.*;
public class IOUringServerChannelConfig extends IOUringChannelConfig implements ServerSocketChannelConfig { public class IOUringServerChannelConfig extends IOUringChannelConfig implements ServerSocketChannelConfig {
private volatile int backlog = NetUtil.SOMAXCONN; private volatile int backlog = NetUtil.SOMAXCONN;
private volatile int pendingFastOpenRequestsThreshold;
IOUringServerChannelConfig(AbstractIOUringServerChannel channel) { IOUringServerChannelConfig(AbstractIOUringServerChannel channel) {
super(channel); super(channel);

View File

@ -23,7 +23,7 @@ import io.netty.channel.unix.Socket;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
public class IOUringServerSocketChannel extends AbstractIOUringServerChannel implements ServerSocketChannel { public final class IOUringServerSocketChannel extends AbstractIOUringServerChannel implements ServerSocketChannel {
private final IOUringServerSocketChannelConfig config; private final IOUringServerSocketChannelConfig config;
public IOUringServerSocketChannel() { public IOUringServerSocketChannel() {

View File

@ -32,7 +32,7 @@ import io.netty.channel.unix.FileDescriptor;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
public class IOUringSocketChannel extends AbstractIOUringChannel implements SocketChannel { public final class IOUringSocketChannel extends AbstractIOUringChannel implements SocketChannel {
private final IOUringSocketChannelConfig config; private final IOUringSocketChannelConfig config;
IOUringSocketChannel(final Channel parent, final LinuxSocket fd) { IOUringSocketChannel(final Channel parent, final LinuxSocket fd) {

View File

@ -17,7 +17,7 @@ package io.netty.channel.uring;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
public class IOUringSubmissionQueue { final class IOUringSubmissionQueue {
private static final int SQE_SIZE = 64; private static final int SQE_SIZE = 64;
private static final int INT_SIZE = Integer.BYTES; //no 32 Bit support? 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 long ringAddress;
private final int ringFd; 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 fFlagsAdress, long kDroppedAddress, long arrayAddress,
long submissionQueueArrayAddress, int ringSize, long submissionQueueArrayAddress, int ringSize,
long ringAddress, int ringFd) { long ringAddress, int ringFd) {

View File

@ -17,10 +17,10 @@ package io.netty.channel.uring;
import io.netty.channel.unix.Socket; import io.netty.channel.unix.Socket;
public class LinuxSocket extends Socket { final class LinuxSocket extends Socket {
private final int fd; private final int fd;
public LinuxSocket(final int fd) { LinuxSocket(final int fd) {
super(fd); super(fd);
this.fd = fd; this.fd = fd;
} }

View File

@ -15,19 +15,14 @@
*/ */
package io.netty.channel.uring; package io.netty.channel.uring;
import io.netty.channel.unix.FileDescriptor;
import io.netty.channel.unix.Socket; import io.netty.channel.unix.Socket;
import io.netty.util.internal.NativeLibraryLoader; import io.netty.util.internal.NativeLibraryLoader;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.ThrowableUtil; 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; 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); private static final int DEFAULT_RING_SIZE = SystemPropertyUtil.getInt("io.netty.uring.ringSize", 32);
static { static {
@ -50,7 +45,7 @@ public final class Native {
public static native int ioUringEnter(int ringFd, int toSubmit, int minComplete, int flags); public static native int ioUringEnter(int ringFd, int toSubmit, int minComplete, int flags);
// for testing(it is only temporary) // for testing(it is only temporary)
public static native long createFile(); public static native int createFile();
private Native() { private Native() {
// utility // utility

View File

@ -16,7 +16,7 @@
package io.netty.channel.uring; package io.netty.channel.uring;
class RingBuffer { final class RingBuffer {
private final IOUringSubmissionQueue ioUringSubmissionQueue; private final IOUringSubmissionQueue ioUringSubmissionQueue;
private final IOUringCompletionQueue ioUringCompletionQueue; private final IOUringCompletionQueue ioUringCompletionQueue;

View File

@ -14,6 +14,7 @@
* under the License. * 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; package io.netty.channel.uring;

View File

@ -15,16 +15,10 @@
*/ */
package io.netty.channel.uring; package io.netty.channel.uring;
import io.netty.channel.unix.Socket;
import org.junit.Test; import org.junit.Test;
import java.nio.charset.Charset;
import java.io.FileInputStream;
import java.io.File;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.buffer.UnpooledUnsafeDirectByteBuf;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -37,8 +31,7 @@ public class NativeTest {
ByteBufAllocator allocator = new UnpooledByteBufAllocator(true); ByteBufAllocator allocator = new UnpooledByteBufAllocator(true);
ByteBuf writeEventByteBuf = allocator.directBuffer(100); ByteBuf writeEventByteBuf = allocator.directBuffer(100);
String inputString = "Hello World!"; String inputString = "Hello World!";
byte[] byteArrray = inputString.getBytes(); writeEventByteBuf.writeCharSequence(inputString, Charset.forName("UTF-8"));
writeEventByteBuf.writeBytes(byteArrray);
int fd = (int) Native.createFile(); int fd = (int) Native.createFile();
@ -73,7 +66,7 @@ public class NativeTest {
byte[] dataRead = new byte[inputString.length()]; byte[] dataRead = new byte[inputString.length()];
readEventByteBuf.readBytes(dataRead); readEventByteBuf.readBytes(dataRead);
assertEquals(inputString, new String(dataRead)); assertArrayEquals(inputString.getBytes(), dataRead);
readEventByteBuf.release(); readEventByteBuf.release();
} }
} }

View File

@ -201,6 +201,7 @@ public class FileDescriptor {
} }
static boolean isClosed(int state) { static boolean isClosed(int state) {
System.out.println("State: " + state);
return (state & STATE_CLOSED_MASK) != 0; return (state & STATE_CLOSED_MASK) != 0;
} }