Make sure the local / remote InetSocketAddres can be obtained. Part of [#2262]

Motivation:
Make sure the remote/local InetSocketAddress can be obtained correctly

Modifications:
Set the remote/local InetSocketAddress after a bind/connect operation was performed

Result:
It is possible to still access the informations even after the fd became invalid. This mirror the behaviour of NIO.
This commit is contained in:
Norman Maurer 2014-03-22 15:01:49 +01:00
parent 6bce61bf1b
commit 32ccdcdb18
2 changed files with 8 additions and 4 deletions

View File

@ -49,7 +49,7 @@ public final class EpollServerSocketChannel extends AbstractEpollChannel impleme
InetSocketAddress addr = (InetSocketAddress) localAddress;
checkResolvable(addr);
Native.bind(fd, addr.getAddress(), addr.getPort());
local = addr;
local = Native.localAddress(fd);
Native.listen(fd, config.getBacklog());
active = true;
}

View File

@ -41,7 +41,6 @@ import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -62,6 +61,8 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
private ScheduledFuture<?> connectTimeoutFuture;
private SocketAddress requestedRemoteAddress;
private volatile InetSocketAddress local;
private volatile InetSocketAddress remote;
private volatile boolean inputShutdown;
private volatile boolean outputShutdown;
@ -82,18 +83,19 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
@Override
protected SocketAddress localAddress0() {
return Native.localAddress(fd);
return local;
}
@Override
protected SocketAddress remoteAddress0() {
return Native.remoteAddress(fd);
return remote;
}
@Override
protected void doBind(SocketAddress local) throws Exception {
InetSocketAddress localAddress = (InetSocketAddress) local;
Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
this.local = Native.localAddress(fd);
}
private void setEpollOut() {
@ -538,6 +540,8 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
checkResolvable(remoteAddress);
boolean connected = Native.connect(fd, remoteAddress.getAddress(),
remoteAddress.getPort());
remote = remoteAddress;
local = Native.localAddress(fd);
if (!connected) {
setEpollOut();
}