diff --git a/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpIo.java b/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpIo.java index 6bb97ae..0a0b67d 100644 --- a/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpIo.java +++ b/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpIo.java @@ -31,7 +31,6 @@ public A4TcpIo(SelectionKey channelKey, SocketChannel rawChannel) { this.channelKey = Objects.requireNonNull(channelKey); this.id = this.channel.socket().toString(); this.bufferSize = rawChannel.socket().getReceiveBufferSize(); - allocateBuffer(); } catch (Exception e) { throw new IllegalStateException("Client-Server channel initialization error - " + rawChannel.socket(), e); } @@ -53,16 +52,11 @@ public A4TcpIo(InetSocketAddress dest, Selector selector, boolean openTls, Execu this.channelKey = chn.register(selector, SelectionKey.OP_READ); this.id = channel.socket().toString(); this.bufferSize = chn.socket().getReceiveBufferSize(); - allocateBuffer(); } catch (Exception e) { throw new IllegalStateException("Server-Backend channel initialization error - " + dest, e); } } - private void allocateBuffer() { - bufferPool.offer(ByteBuffer.allocateDirect(bufferSize)); - } - private ByteBuffer getBuffer() { ByteBuffer buffer = bufferPool.poll(); if (buffer == null) { @@ -127,7 +121,7 @@ public SocketChannel getRawChannel() { ? ((SSLSocketChannel) c).getWrappedSocketChannel().socket() : c.socket(); return format( - "[%s, bq%02d, bp%02d, %02d, %02d, %s %s %s]", + "[%s, bq%02d, bp%02d, i%02d, r%02d, %s %s %s]", format("%s%s%s%s", k.isReadable() ? "r" : "", k.isWritable() ? "w" : "", diff --git a/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpSess.java b/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpSess.java index 7e8538c..cef506a 100644 --- a/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpSess.java +++ b/a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpSess.java @@ -180,6 +180,9 @@ private void tcpUpdate(SelectionKey key) { } } else if (bytes == 0 && tlsClient) { initBackend(); + } else if (bytes == -1 && isBk && !backend.bufferQueue.isEmpty()) { + client.channelKey.interestOps(SelectionKey.OP_WRITE); + backend.channelKey.interestOps(0); } else if (bytes == -1) { tearDown(null); } diff --git a/build.gradle.kts b/build.gradle.kts index 0d5b2b2..7724caa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("io.vacco.oss.gitflow") version "1.0.1" apply(false) } subprojects { apply(plugin = "io.vacco.oss.gitflow") group = "io.vacco.awe4lb" - version = "0.2.0" + version = "0.2.1" configure { addClasspathHell()