Make most outbound operations are cancellable

- Inspired by #2214
- It actually reduces the chance of trying to marking a cancelled promise as success again, which raises an IllegalStateException.
This commit is contained in:
Trustin Lee 2014-02-10 14:04:47 -08:00
parent c7087c6842
commit a34d5baad2
3 changed files with 12 additions and 9 deletions

View File

@ -134,7 +134,7 @@ public class RxtxChannel extends OioByteStreamChannel {
public void connect(
final SocketAddress remoteAddress,
final SocketAddress localAddress, final ChannelPromise promise) {
if (!ensureOpen(promise)) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}

View File

@ -418,7 +418,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
try {
// check if the channel is still open as it could be closed in the mean time when the register
// call was outside of the eventLoop
if (!ensureOpen(promise)) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}
doRegister();
@ -442,7 +442,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
@Override
public final void bind(final SocketAddress localAddress, final ChannelPromise promise) {
if (!ensureOpen(promise)) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}
@ -480,6 +480,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
@Override
public final void disconnect(final ChannelPromise promise) {
if (!promise.setUncancellable()) {
return;
}
boolean wasActive = isActive();
try {
doDisconnect();
@ -502,6 +506,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
@Override
public final void close(final ChannelPromise promise) {
if (!promise.setUncancellable()) {
return;
}
if (inFlush0) {
invokeLater(new Runnable() {
@Override

View File

@ -55,12 +55,7 @@ public abstract class AbstractOioChannel extends AbstractChannel {
public void connect(
final SocketAddress remoteAddress,
final SocketAddress localAddress, final ChannelPromise promise) {
if (!ensureOpen(promise)) {
return;
}
if (!promise.setUncancellable()) {
close(voidPromise());
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}