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:
parent
838e80ed6b
commit
041d37e0c8
@ -133,7 +133,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;
|
||||
}
|
||||
|
||||
|
@ -433,7 +433,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();
|
||||
@ -457,7 +457,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;
|
||||
}
|
||||
|
||||
@ -496,6 +496,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();
|
||||
@ -518,6 +522,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
|
||||
@ -577,6 +585,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
|
||||
@Override
|
||||
public final void deregister(final ChannelPromise promise) {
|
||||
if (!promise.setUncancellable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registered) {
|
||||
promise.setSuccess();
|
||||
return;
|
||||
|
@ -58,12 +58,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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user