AsyncNioConnection优化

This commit is contained in:
redkale
2023-01-30 13:53:03 +08:00
parent 823b89ec48
commit 7dc57c67ed

View File

@@ -35,7 +35,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
protected CompletionHandler<Void, Object> connectCompletionHandler;
protected boolean connectPending;
protected volatile boolean connectPending;
protected SelectionKey connectKey;
@@ -48,7 +48,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
protected CompletionHandler<Integer, ByteBuffer> readCompletionHandler;
protected boolean readPending;
protected volatile boolean readPending;
protected SelectionKey readKey;
@@ -88,7 +88,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
protected CompletionHandler<Integer, Object> writeCompletionHandler;
protected boolean writePending;
protected volatile boolean writePending;
protected SelectionKey writeKey;
@@ -285,11 +285,11 @@ abstract class AsyncNioConnection extends AsyncConnection {
public void doWrite(boolean direct) {
try {
this.writetime = System.currentTimeMillis();
final boolean invokeDirect = direct;
int totalCount = 0;
boolean hasRemain = true;
boolean writeCompleted = true;
while (invokeDirect && hasRemain) { //必须要将buffer写完为止
if (direct) {
while (hasRemain) { //必须要将buffer写完为止
if (writeByteTuple1Array != null) {
final ByteBuffer buffer = pollWriteBuffer();
if (buffer.remaining() >= writeByteTuple1Length + writeByteTuple2Length) {
@@ -373,6 +373,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
break;
}
}
}
if (writeCompleted && (totalCount != 0 || !hasRemain)) {
handleWrite(writeTotal + totalCount, null);
@@ -469,8 +470,6 @@ abstract class AsyncNioConnection extends AsyncConnection {
ByteBuffer bb;
int count;
@Override
public synchronized int read() throws IOException {
if (bb == null || !bb.hasRemaining()) {