Fix a runtime type cast exception when calling RxtxChannel.local/remoteAddress()

This commit is contained in:
Trustin Lee 2013-01-10 14:01:17 +09:00
parent b5e6350bcb
commit 793a571465
4 changed files with 43 additions and 18 deletions

View File

@ -20,7 +20,6 @@ import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import io.netty.buffer.BufType;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.socket.oio.AbstractOioByteChannel;
@ -37,10 +36,13 @@ import static io.netty.transport.rxtx.RxtxChannelOptions.*;
* A channel to a serial device using the RXTX library.
*/
public class RxtxChannel extends AbstractOioByteChannel {
private static final RxtxDeviceAddress LOCAL_ADDRESS = new RxtxDeviceAddress("localhost");
private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.BYTE, true);
private final ChannelConfig config;
private final RxtxChannelConfig config;
private boolean open = true;
private RxtxDeviceAddress deviceAddress;
private SerialPort serialPort;
private InputStream in;
@ -53,7 +55,7 @@ public class RxtxChannel extends AbstractOioByteChannel {
}
@Override
public ChannelConfig config() {
public RxtxChannelConfig config() {
return config;
}
@ -64,7 +66,7 @@ public class RxtxChannel extends AbstractOioByteChannel {
@Override
public boolean isOpen() {
return true;
return open;
}
@Override
@ -121,12 +123,22 @@ public class RxtxChannel extends AbstractOioByteChannel {
}
@Override
protected SocketAddress localAddress0() {
return null;
public RxtxDeviceAddress localAddress() {
return (RxtxDeviceAddress) super.localAddress();
}
@Override
protected SocketAddress remoteAddress0() {
public RxtxDeviceAddress remoteAddress() {
return (RxtxDeviceAddress) super.remoteAddress();
}
@Override
protected RxtxDeviceAddress localAddress0() {
return LOCAL_ADDRESS;
}
@Override
protected RxtxDeviceAddress remoteAddress0() {
return deviceAddress;
}
@ -142,6 +154,8 @@ public class RxtxChannel extends AbstractOioByteChannel {
@Override
protected void doClose() throws Exception {
open = false;
IOException ex = null;
try {

View File

@ -20,7 +20,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
/**
@ -47,16 +46,6 @@ public abstract class AbstractOioChannel extends AbstractChannel {
super(parent, id);
}
@Override
public InetSocketAddress localAddress() {
return (InetSocketAddress) super.localAddress();
}
@Override
public InetSocketAddress remoteAddress() {
return (InetSocketAddress) super.remoteAddress();
}
@Override
protected AbstractUnsafe newUnsafe() {
return new DefaultOioUnsafe();

View File

@ -20,6 +20,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import java.io.IOException;
import java.net.InetSocketAddress;
/**
* Abstract base class for OIO which reads and writes objects from/to a Socket
@ -33,6 +34,16 @@ public abstract class AbstractOioMessageChannel extends AbstractOioChannel {
super(parent, id);
}
@Override
public InetSocketAddress localAddress() {
return (InetSocketAddress) super.localAddress();
}
@Override
public InetSocketAddress remoteAddress() {
return (InetSocketAddress) super.remoteAddress();
}
@Override
protected void doRead() {
final ChannelPipeline pipeline = pipeline();

View File

@ -33,6 +33,7 @@ import io.netty.logging.InternalLoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
@ -163,6 +164,16 @@ public class OioSocketChannel extends AbstractOioByteChannel
return future;
}
@Override
public InetSocketAddress localAddress() {
return (InetSocketAddress) super.localAddress();
}
@Override
public InetSocketAddress remoteAddress() {
return (InetSocketAddress) super.remoteAddress();
}
@Override
protected SocketAddress localAddress0() {
return socket.getLocalSocketAddress();