From fecfadb853cc1c4dabc58a1a680c224873f97445 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 9 Jul 2009 06:29:03 +0000 Subject: [PATCH] Fixed issue: NETTY-191 Raise ChannelClosedException only once when many queued write requests failed. --- .../netty/channel/socket/nio/NioDatagramWorker.java | 10 +++++++--- .../org/jboss/netty/channel/socket/nio/NioWorker.java | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java index dcfd744de5..3b914d5762 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioDatagramWorker.java @@ -679,6 +679,7 @@ class NioDatagramWorker implements Runnable { private static void cleanUpWriteBuffer(final NioDatagramChannel channel) { Exception cause = null; + boolean fireExceptionCaught = false; // Clean up the stale messages in the write buffer. synchronized (channel.writeLock) { @@ -694,8 +695,7 @@ class NioDatagramWorker implements Runnable { cause = new ClosedChannelException(); } evt.getFuture().setFailure(cause); - - fireExceptionCaught(channel, cause); + fireExceptionCaught = true; } Queue writeBuffer = channel.writeBufferQueue; @@ -716,10 +716,14 @@ class NioDatagramWorker implements Runnable { break; } evt.getFuture().setFailure(cause); - fireExceptionCaught(channel, cause); + fireExceptionCaught = true; } } } + + if (fireExceptionCaught) { + fireExceptionCaught(channel, cause); + } } static void setInterestOps(final NioDatagramChannel channel, diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index 4a18f17e5f..7cf77c5ced 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -593,6 +593,7 @@ class NioWorker implements Runnable { private static void cleanUpWriteBuffer(NioSocketChannel channel) { Exception cause = null; + boolean fireExceptionCaught = false; // Clean up the stale messages in the write buffer. synchronized (channel.writeLock) { @@ -609,8 +610,7 @@ class NioWorker implements Runnable { cause = new ClosedChannelException(); } evt.getFuture().setFailure(cause); - - fireExceptionCaught(channel, cause); + fireExceptionCaught = true; } Queue writeBuffer = channel.writeBuffer; @@ -631,10 +631,14 @@ class NioWorker implements Runnable { break; } evt.getFuture().setFailure(cause); - fireExceptionCaught(channel, cause); + fireExceptionCaught = true; } } } + + if (fireExceptionCaught) { + fireExceptionCaught(channel, cause); + } } static void setInterestOps(