Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/netty/netty
Browse files Browse the repository at this point in the history
  • Loading branch information
normanmaurer committed Aug 7, 2012
2 parents 947f3bc + b09e945 commit 3ed3827
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static AsynchronousSocketChannel newSocket(AsynchronousChannelGroup grou
private boolean flushing;

private final AtomicBoolean readSuspended = new AtomicBoolean();
private final AtomicBoolean readInProgress = new AtomicBoolean();

private final Runnable readTask = new Runnable() {
@Override
Expand Down Expand Up @@ -191,6 +192,11 @@ private void beginRead() {
return;
}

// prevent ReadPendingException
if (!readInProgress.compareAndSet(false, true)) {
return;
}

ByteBuf byteBuf = pipeline().inboundByteBuffer();
if (!byteBuf.readable()) {
byteBuf.discardReadBytes();
Expand Down Expand Up @@ -297,6 +303,9 @@ protected void completed0(Integer result, AioSocketChannel channel) {
}
}
} finally {
// see beginRead
channel.readInProgress.set(false);

if (read) {
if (!channel.readSuspended.get()) {
pipeline.fireInboundBufferUpdated();
Expand Down

0 comments on commit 3ed3827

Please sign in to comment.