Skip to content

Commit

Permalink
Remove unnecessary inEventLoop() checks in Channel.Unsafe
Browse files Browse the repository at this point in the history
.. because HeadHandler in the pipeline always ensures those methods are always invoked from the correct I/O thread
  • Loading branch information
trustin committed May 17, 2013
1 parent 41f5d56 commit fd1d31e
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 407 deletions.
76 changes: 33 additions & 43 deletions transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package io.netty.channel.rxtx;

import static io.netty.channel.rxtx.RxtxChannelOption.*;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import io.netty.channel.ChannelPromise;
import io.netty.channel.oio.OioByteStreamChannel;

import java.net.SocketAddress;
import java.util.concurrent.TimeUnit;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import static io.netty.channel.rxtx.RxtxChannelOption.*;

/**
* A channel to a serial device using the RXTX library.
Expand Down Expand Up @@ -134,50 +133,41 @@ private final class RxtxUnsafe extends AbstractUnsafe {
public void connect(
final SocketAddress remoteAddress,
final SocketAddress localAddress, final ChannelPromise promise) {
if (eventLoop().inEventLoop()) {
if (!ensureOpen(promise)) {
return;
}
if (!ensureOpen(promise)) {
return;
}

try {
final boolean wasActive = isActive();
doConnect(remoteAddress, localAddress);

int waitTime = config().getOption(WAIT_TIME);
if (waitTime > 0) {
eventLoop().schedule(new Runnable() {
@Override
public void run() {
try {
doInit();
promise.setSuccess();
if (!wasActive && isActive()) {
pipeline().fireChannelActive();
}
} catch (Throwable t) {
promise.setFailure(t);
closeIfClosed();
try {
final boolean wasActive = isActive();
doConnect(remoteAddress, localAddress);

int waitTime = config().getOption(WAIT_TIME);
if (waitTime > 0) {
eventLoop().schedule(new Runnable() {
@Override
public void run() {
try {
doInit();
promise.setSuccess();
if (!wasActive && isActive()) {
pipeline().fireChannelActive();
}
} catch (Throwable t) {
promise.setFailure(t);
closeIfClosed();
}
}, waitTime, TimeUnit.MILLISECONDS);
} else {
doInit();
promise.setSuccess();
if (!wasActive && isActive()) {
pipeline().fireChannelActive();
}
}, waitTime, TimeUnit.MILLISECONDS);
} else {
doInit();
promise.setSuccess();
if (!wasActive && isActive()) {
pipeline().fireChannelActive();
}
} catch (Throwable t) {
promise.setFailure(t);
closeIfClosed();
}
} else {
eventLoop().execute(new Runnable() {
@Override
public void run() {
connect(remoteAddress, localAddress, promise);
}
});
} catch (Throwable t) {
promise.setFailure(t);
closeIfClosed();
}
}
}
Expand Down
Loading

0 comments on commit fd1d31e

Please sign in to comment.