Tidy up AbstractChannel.read()
This commit is contained in:
parent
3a8c10cc5a
commit
cab983244d
@ -639,17 +639,16 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
|
|
||||||
final ChannelBufferHolder<Object> buf = pipeline().nextIn();
|
final ChannelBufferHolder<Object> buf = pipeline().nextIn();
|
||||||
final boolean hasByteBuffer = buf.hasByteBuffer();
|
|
||||||
|
|
||||||
long readAmount = 0;
|
|
||||||
boolean closed = false;
|
boolean closed = false;
|
||||||
|
boolean read = false;
|
||||||
try {
|
try {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int localReadAmount = doRead(buf);
|
int localReadAmount = doRead(buf);
|
||||||
if (localReadAmount > 0) {
|
if (localReadAmount > 0) {
|
||||||
readAmount += localReadAmount;
|
expandReadBuffer(buf);
|
||||||
|
read = true;
|
||||||
} else if (localReadAmount == 0) {
|
} else if (localReadAmount == 0) {
|
||||||
if (!expandReadBuffer(buf, hasByteBuffer)) {
|
if (!expandReadBuffer(buf)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (localReadAmount < 0) {
|
} else if (localReadAmount < 0) {
|
||||||
@ -657,16 +656,19 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
if (readAmount > 0) {
|
if (read) {
|
||||||
|
read = false;
|
||||||
pipeline.fireInboundBufferUpdated();
|
pipeline.fireInboundBufferUpdated();
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
|
||||||
pipeline().fireExceptionCaught(t);
|
pipeline().fireExceptionCaught(t);
|
||||||
if (t instanceof IOException) {
|
if (t instanceof IOException) {
|
||||||
close(voidFuture());
|
close(voidFuture());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if (read) {
|
||||||
|
pipeline.fireInboundBufferUpdated();
|
||||||
|
}
|
||||||
if (closed && isOpen()) {
|
if (closed && isOpen()) {
|
||||||
close(voidFuture());
|
close(voidFuture());
|
||||||
}
|
}
|
||||||
@ -859,8 +861,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
protected abstract int doFlush(boolean lastSpin) throws Exception;
|
protected abstract int doFlush(boolean lastSpin) throws Exception;
|
||||||
protected abstract boolean inEventLoopDrivenFlush();
|
protected abstract boolean inEventLoopDrivenFlush();
|
||||||
|
|
||||||
private static boolean expandReadBuffer(ChannelBufferHolder<Object> buf, boolean hasByteBuffer) {
|
private static boolean expandReadBuffer(ChannelBufferHolder<Object> buf) {
|
||||||
if (!hasByteBuffer) {
|
if (!buf.hasByteBuffer()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user