AsyncNioConnection优化
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user