WIP
This commit is contained in:
parent
ddb503f76d
commit
381493999d
@ -37,6 +37,7 @@ import io.netty.channel.socket.SocketChannelConfig;
|
||||
import io.netty.channel.unix.Buffer;
|
||||
import io.netty.channel.unix.Errors;
|
||||
import io.netty.channel.unix.FileDescriptor;
|
||||
import io.netty.channel.unix.IovArray;
|
||||
import io.netty.channel.unix.NativeInetAddress;
|
||||
import io.netty.channel.unix.Socket;
|
||||
import io.netty.channel.unix.UnixChannel;
|
||||
@ -89,9 +90,6 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
|
||||
private volatile SocketAddress local;
|
||||
private volatile SocketAddress remote;
|
||||
|
||||
//to release it
|
||||
private long iovecMemoryAddress = -1;
|
||||
|
||||
AbstractIOUringChannel(final Channel parent, LinuxSocket socket) {
|
||||
super(parent);
|
||||
this.socket = checkNotNull(socket, "fd");
|
||||
@ -305,25 +303,30 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
|
||||
|
||||
private void doWriteMultiple(ChannelOutboundBuffer in) {
|
||||
|
||||
final IovecArrayPool iovecArray = ((IOUringEventLoop) eventLoop()).getIovecArrayPool();
|
||||
final IovArray iovecArray = ((IOUringEventLoop) eventLoop()).getIovArray();
|
||||
int offset = iovecArray.count();
|
||||
try {
|
||||
in.forEachFlushedMessage(iovecArray);
|
||||
|
||||
iovecMemoryAddress = iovecArray.createNewIovecMemoryAddress();
|
||||
if (iovecMemoryAddress != -1) {
|
||||
try {
|
||||
in.forEachFlushedMessage(iovecArray);
|
||||
} catch (Exception e) {
|
||||
// This should never happem, anyway fallback to single write.
|
||||
doWriteSingle((ByteBuf) in.current());
|
||||
}
|
||||
int count = iovecArray.count() - offset;
|
||||
if (count > 0) {
|
||||
submissionQueue().addWritev(socket.intValue(), iovecArray.memoryAddress(offset), count);
|
||||
submissionQueue().submit();
|
||||
|
||||
if (iovecArray.count() > 0) {
|
||||
submissionQueue().addWritev(socket.intValue(), iovecMemoryAddress, iovecArray.count());
|
||||
ioState |= WRITE_SCHEDULED;
|
||||
if (iovecArray.isFull()) {
|
||||
submissionQueue().submit();
|
||||
iovecArray.clear();
|
||||
}
|
||||
} else {
|
||||
in.removeBytes(0);
|
||||
}
|
||||
} else {
|
||||
// We were not be able to create a new iovec, fallback to single write.
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// This should never happem, anyway fallback to single write.
|
||||
doWriteSingle((ByteBuf) in.current());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final void doWriteSingle(ByteBuf buf) {
|
||||
@ -545,10 +548,6 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
|
||||
ioState &= ~WRITE_SCHEDULED;
|
||||
|
||||
ChannelOutboundBuffer channelOutboundBuffer = unsafe().outboundBuffer();
|
||||
if (iovecMemoryAddress != -1) {
|
||||
((IOUringEventLoop) eventLoop()).getIovecArrayPool().releaseIovec(iovecMemoryAddress);
|
||||
iovecMemoryAddress = -1;
|
||||
}
|
||||
if (res >= 0) {
|
||||
channelOutboundBuffer.removeBytes(res);
|
||||
doWrite(channelOutboundBuffer);
|
||||
|
@ -19,6 +19,7 @@ import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.SingleThreadEventLoop;
|
||||
import io.netty.channel.unix.Errors;
|
||||
import io.netty.channel.unix.FileDescriptor;
|
||||
import io.netty.channel.unix.IovArray;
|
||||
import io.netty.util.collection.IntObjectHashMap;
|
||||
import io.netty.util.collection.IntObjectMap;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
@ -46,7 +47,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
|
||||
// other value T when EL is waiting with wakeup scheduled at time T
|
||||
private final AtomicLong nextWakeupNanos = new AtomicLong(AWAKE);
|
||||
private final FileDescriptor eventfd;
|
||||
private final IovecArrayPool iovecArrayPool;
|
||||
private final IovArray iovArray;
|
||||
|
||||
private long prevDeadlineNanos = NONE;
|
||||
private boolean pendingWakeup;
|
||||
@ -57,7 +58,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
|
||||
ringBuffer = Native.createRingBuffer();
|
||||
eventfd = Native.newEventFd();
|
||||
logger.trace("New EventLoop: {}", this.toString());
|
||||
iovecArrayPool = new IovecArrayPool();
|
||||
iovArray = new IovArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,10 +152,12 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
|
||||
runAllTasks();
|
||||
|
||||
submissionQueue.submit();
|
||||
iovArray.clear();
|
||||
try {
|
||||
if (isShuttingDown()) {
|
||||
closeAll();
|
||||
submissionQueue.submit();
|
||||
iovArray.clear();
|
||||
if (confirmShutdown()) {
|
||||
break;
|
||||
}
|
||||
@ -253,7 +256,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
|
||||
logger.warn("Failed to close the event fd.", e);
|
||||
}
|
||||
ringBuffer.close();
|
||||
iovecArrayPool.release();
|
||||
iovArray.release();
|
||||
}
|
||||
|
||||
public RingBuffer getRingBuffer() {
|
||||
@ -268,7 +271,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
|
||||
}
|
||||
}
|
||||
|
||||
public IovecArrayPool getIovecArrayPool() {
|
||||
return iovecArrayPool;
|
||||
public IovArray getIovArray() {
|
||||
return iovArray;
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +153,10 @@ public final class IovArray implements MessageProcessor {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return count >= IOV_SIZE || size >= maxBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number if iov entries.
|
||||
*/
|
||||
|
@ -336,7 +336,7 @@ public final class ChannelOutboundBuffer {
|
||||
for (;;) {
|
||||
Object msg = current();
|
||||
if (!(msg instanceof ByteBuf)) {
|
||||
assert writtenBytes == 0;
|
||||
assert writtenBytes == 0 : "writtenBytes: " + writtenBytes;
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user