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>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-io_uring</artifactId>

View File

@ -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'

View File

@ -17,48 +17,51 @@
#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;
unsigned *ktail;
unsigned *kring_mask;
unsigned *kring_entries;
unsigned *kflags;
unsigned *kdropped;
unsigned *array;
struct io_uring_sqe *sqes;
unsigned *khead;
unsigned *ktail;
unsigned *kring_mask;
unsigned *kring_entries;
unsigned *kflags;
unsigned *kdropped;
unsigned *array;
struct io_uring_sqe *sqes;
unsigned sqe_head;
unsigned sqe_tail;
unsigned sqe_head;
unsigned sqe_tail;
size_t ring_sz;
void *ring_ptr;
size_t ring_sz;
void *ring_ptr;
};
struct io_uring_cq {
unsigned *khead;
unsigned *ktail;
unsigned *kring_mask;
unsigned *kring_entries;
unsigned *koverflow;
struct io_uring_cqe *cqes;
unsigned *khead;
unsigned *ktail;
unsigned *kring_mask;
unsigned *kring_entries;
unsigned *koverflow;
struct io_uring_cqe *cqes;
size_t ring_sz;
void *ring_ptr;
size_t ring_sz;
void *ring_ptr;
};
struct io_uring {
struct io_uring_sq sq;
struct io_uring_cq cq;
unsigned flags;
int ring_fd;
struct io_uring_sq sq;
struct io_uring_cq cq;
unsigned flags;
int ring_fd;
};
#endif

View File

@ -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;
@ -72,183 +64,190 @@ static jclass ioUringCompletionQueueClass = NULL;
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)
munmap(cq->ring_ptr, cq->ring_sz);
munmap(sq->ring_ptr, sq->ring_sz);
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) {
size_t size;
int ret;
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;
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);
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);
if (p->features & IORING_FEAT_SINGLE_MMAP) {
if (cq->ring_sz > sq->ring_sz)
sq->ring_sz = cq->ring_sz;
cq->ring_sz = sq->ring_sz;
}
sq->ring_ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING);
if (sq->ring_ptr == MAP_FAILED)
return -errno;
if (p->features & IORING_FEAT_SINGLE_MMAP) {
if (cq->ring_sz > sq->ring_sz)
sq->ring_sz = cq->ring_sz;
cq->ring_sz = sq->ring_sz;
}
sq->ring_ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING);
if (sq->ring_ptr == MAP_FAILED)
return -errno;
if (p->features & IORING_FEAT_SINGLE_MMAP) {
cq->ring_ptr = sq->ring_ptr;
} else {
cq->ring_ptr = mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING);
if (cq->ring_ptr == MAP_FAILED) {
cq->ring_ptr = NULL;
ret = -errno;
goto err;
}
}
if (p->features & IORING_FEAT_SINGLE_MMAP) {
cq->ring_ptr = sq->ring_ptr;
} else {
cq->ring_ptr = mmap(0, cq->ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING);
if (cq->ring_ptr == MAP_FAILED) {
cq->ring_ptr = NULL;
ret = -errno;
goto err;
}
}
sq->khead = sq->ring_ptr + p->sq_off.head;
sq->ktail = sq->ring_ptr + p->sq_off.tail;
sq->kring_mask = sq->ring_ptr + p->sq_off.ring_mask;
sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries;
sq->kflags = sq->ring_ptr + p->sq_off.flags;
sq->kdropped = sq->ring_ptr + p->sq_off.dropped;
sq->array = sq->ring_ptr + p->sq_off.array;
sq->khead = sq->ring_ptr + p->sq_off.head;
sq->ktail = sq->ring_ptr + p->sq_off.tail;
sq->kring_mask = sq->ring_ptr + p->sq_off.ring_mask;
sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries;
sq->kflags = sq->ring_ptr + p->sq_off.flags;
sq->kdropped = sq->ring_ptr + p->sq_off.dropped;
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);
if (sq->sqes == MAP_FAILED) {
ret = -errno;
err:
io_uring_unmap_rings(sq, cq);
return ret;
}
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);
if (sq->sqes == MAP_FAILED) {
ret = -errno;
goto err;
}
cq->khead = cq->ring_ptr + p->cq_off.head;
cq->ktail = cq->ring_ptr + p->cq_off.tail;
cq->kring_mask = cq->ring_ptr + p->cq_off.ring_mask;
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;
cq->khead = cq->ring_ptr + p->cq_off.head;
cq->ktail = cq->ring_ptr + p->cq_off.tail;
cq->kring_mask = cq->ring_ptr + p->cq_off.ring_mask;
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,
struct io_uring_params *p) {
int ret;
int ret;
ret = io_uring_mmap(ring_fd, p, &io_uring_ring->sq, &io_uring_ring->cq);
if (!ret) {
io_uring_ring->flags = p->flags;
io_uring_ring->ring_fd = ring_fd;
} else {
perror("setup_io_uring error \n");
}
ret = io_uring_mmap(ring_fd, p, &io_uring_ring->sq, &io_uring_ring->cq);
if (!ret) {
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");
}
}
static jint netty_io_uring_enter(JNIEnv *env, jclass class1, jint ring_fd, jint to_submit,
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) {
struct io_uring_params p;
memset(&p, 0, sizeof(p));
struct io_uring_params 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
if (ring_fd < -1) {
//Todo
if (ring_fd < -1) {
//throw Exception
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;
//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,
(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 ioUringSubmissionQueue = (*env)->NewObject(
env, ioUringSubmissionQueueClass, ioUringSubmissionQueueMethodId,
(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,
jobject ringBuffer =
(*env)->NewObject(env, ringBufferClass, ringBufferMethodId,
ioUringSubmissionQueue, ioUringCompletionQueue);
return ringBuffer;
return ringBuffer;
}
static jlong netty_create_file(JNIEnv *env, jclass class) {
return open("io-uring-test.txt", O_RDWR | O_TRUNC | O_CREAT, 0644);
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]);
// JNI Method Registration Table End
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env;
char *nettyClassName = NULL;
JNIEnv *env;
char *nettyClassName = NULL;
if ((*vm)->GetEnv(vm, (void **)&env, NETTY_JNI_VERSION) != JNI_OK) {
return JNI_ERR;
}
char *packagePrefix = NULL;
if ((*vm)->GetEnv(vm, (void **)&env, NETTY_JNI_VERSION) != JNI_OK) {
return JNI_ERR;
}
char *packagePrefix = NULL;
Dl_info dlinfo;
jint status = 0;
Dl_info dlinfo;
jint status = 0;
if (!dladdr((void *)netty_io_uring_native_JNI_OnUnLoad, &dlinfo)) {
fprintf(stderr,
if (!dladdr((void *)netty_io_uring_native_JNI_OnUnLoad, &dlinfo)) {
fprintf(stderr,
"FATAL: transport-native-epoll JNI call to dladdr failed!\n");
return JNI_ERR;
}
packagePrefix = netty_unix_util_parse_package_prefix(
return JNI_ERR;
}
packagePrefix = netty_unix_util_parse_package_prefix(
dlinfo.dli_fname, "netty_transport_native_io_uring", &status);
if (status == JNI_ERR) {
fprintf(stderr,
if (status == JNI_ERR) {
fprintf(stderr,
"FATAL: netty_transport_native_io_uring JNI encountered unexpected "
"dlinfo.dli_fname: %s\n",
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",
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) {
goto done;
}
@ -269,30 +268,30 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
goto done;
}
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer",
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer",
nettyClassName, done);
NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done);
NETTY_GET_METHOD(env, ringBufferClass, ringBufferMethodId, "<init>",
NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done);
NETTY_GET_METHOD(env, ringBufferClass, ringBufferMethodId, "<init>",
"(Lio/netty/channel/uring/IOUringSubmissionQueue;Lio/netty/"
"channel/uring/IOUringCompletionQueue;)V",
done);
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringSubmissionQueue",
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringSubmissionQueue",
nettyClassName, done);
NETTY_LOAD_CLASS(env, ioUringSubmissionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringSubmissionQueueClass,
NETTY_LOAD_CLASS(env, ioUringSubmissionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringSubmissionQueueClass,
ioUringSubmissionQueueMethodId, "<init>", "(JJJJJJJJIJI)V",
done);
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringCompletionQueue",
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/IOUringCompletionQueue",
nettyClassName, done);
NETTY_LOAD_CLASS(env, ioUringCompletionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringCompletionQueueClass,
NETTY_LOAD_CLASS(env, ioUringCompletionQueueClass, nettyClassName, done);
NETTY_GET_METHOD(env, ioUringCompletionQueueClass,
ioUringCommpletionQueueMethodId, "<init>", "(JJJJJJIJI)V",
done);
done:
//unload
done:
//unload
return NETTY_JNI_VERSION;
return NETTY_JNI_VERSION;
}

View File

@ -19,17 +19,12 @@
#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);
return syscall(__NR_io_uring_setup, entries, p);
}
int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
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);
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

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

View File

@ -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() {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

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

View File

@ -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;

View File

@ -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();
}
}

View File

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