Skip to content

Commit

Permalink
Make most outbound operations are cancellable
Browse files Browse the repository at this point in the history
- Inspired by netty#2214
- It actually reduces the chance of trying to marking a cancelled promise as success again, which raises an IllegalStateException.
  • Loading branch information
trustin committed Feb 10, 2014
1 parent c7087c6 commit a34d5ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private final class RxtxUnsafe extends AbstractUnsafe {
public void connect(
final SocketAddress remoteAddress,
final SocketAddress localAddress, final ChannelPromise promise) {
if (!ensureOpen(promise)) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}

Expand Down
12 changes: 10 additions & 2 deletions transport/src/main/java/io/netty/channel/AbstractChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private void register0(ChannelPromise promise) {
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();
Expand All @@ -442,7 +442,7 @@ private void register0(ChannelPromise promise) {

@Override
public final void bind(final SocketAddress localAddress, final ChannelPromise promise) {
if (!ensureOpen(promise)) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
return;
}

Expand Down Expand Up @@ -480,6 +480,10 @@ public void run() {

@Override
public final void disconnect(final ChannelPromise promise) {
if (!promise.setUncancellable()) {
return;
}

boolean wasActive = isActive();
try {
doDisconnect();
Expand All @@ -502,6 +506,10 @@ public void run() {

@Override
public final void close(final ChannelPromise promise) {
if (!promise.setUncancellable()) {
return;
}

if (inFlush0) {
invokeLater(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ private final class DefaultOioUnsafe extends AbstractUnsafe {
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;
}

Expand Down

0 comments on commit a34d5ba

Please sign in to comment.