Clean up AbstractUnsafe#bind and AbstractUnsafe#disconnect.

This commit is contained in:
Jeff Pinner 2013-07-28 13:05:34 -07:00 committed by Norman Maurer
parent bf2430d255
commit 3922c518cd
2 changed files with 44 additions and 37 deletions

View File

@ -412,7 +412,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
}); });
} catch (Throwable t) { } catch (Throwable t) {
logger.warn( logger.warn(
"Force-closing a channel whose registration task was unaccepted by an event loop: {}", "Force-closing a channel whose registration task was not accepted by an event loop: {}",
AbstractChannel.this, t); AbstractChannel.this, t);
closeForcibly(); closeForcibly();
closeFuture.setClosed(); closeFuture.setClosed();
@ -453,9 +453,6 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
return; return;
} }
try {
boolean wasActive = isActive();
// See: https://github.com/netty/netty/issues/576 // See: https://github.com/netty/netty/issues/576
if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() && if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() &&
Boolean.TRUE.equals(config().getOption(ChannelOption.SO_BROADCAST)) && Boolean.TRUE.equals(config().getOption(ChannelOption.SO_BROADCAST)) &&
@ -469,23 +466,35 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
"address (" + localAddress + ") anyway as requested."); "address (" + localAddress + ") anyway as requested.");
} }
boolean wasActive = isActive();
try {
doBind(localAddress); doBind(localAddress);
promise.setSuccess(); } catch (Throwable t) {
closeIfClosed();
promise.setFailure(t);
return;
}
if (!wasActive && isActive()) { if (!wasActive && isActive()) {
invokeLater(new Runnable() {
@Override
public void run() {
pipeline.fireChannelActive(); pipeline.fireChannelActive();
} }
} catch (Throwable t) { });
promise.setFailure(t);
closeIfClosed();
} }
promise.setSuccess();
} }
@Override @Override
public final void disconnect(final ChannelPromise promise) { public final void disconnect(final ChannelPromise promise) {
try {
boolean wasActive = isActive(); boolean wasActive = isActive();
try {
doDisconnect(); doDisconnect();
promise.setSuccess(); } catch (Throwable t) {
closeIfClosed();
promise.setFailure(t);
return;
}
if (wasActive && !isActive()) { if (wasActive && !isActive()) {
invokeLater(new Runnable() { invokeLater(new Runnable() {
@Override @Override
@ -494,10 +503,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
} }
}); });
} }
} catch (Throwable t) { closeIfClosed(); // doDisconnect() might have closed the channel
promise.setFailure(t); promise.setSuccess();
closeIfClosed();
}
} }
@Override @Override