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:
parent
6bce61bf1b
commit
32ccdcdb18
|
@ -49,7 +49,7 @@ public final class EpollServerSocketChannel extends AbstractEpollChannel impleme
|
||||||
InetSocketAddress addr = (InetSocketAddress) localAddress;
|
InetSocketAddress addr = (InetSocketAddress) localAddress;
|
||||||
checkResolvable(addr);
|
checkResolvable(addr);
|
||||||
Native.bind(fd, addr.getAddress(), addr.getPort());
|
Native.bind(fd, addr.getAddress(), addr.getPort());
|
||||||
local = addr;
|
local = Native.localAddress(fd);
|
||||||
Native.listen(fd, config.getBacklog());
|
Native.listen(fd, config.getBacklog());
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -62,6 +61,8 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
||||||
private ScheduledFuture<?> connectTimeoutFuture;
|
private ScheduledFuture<?> connectTimeoutFuture;
|
||||||
private SocketAddress requestedRemoteAddress;
|
private SocketAddress requestedRemoteAddress;
|
||||||
|
|
||||||
|
private volatile InetSocketAddress local;
|
||||||
|
private volatile InetSocketAddress remote;
|
||||||
private volatile boolean inputShutdown;
|
private volatile boolean inputShutdown;
|
||||||
private volatile boolean outputShutdown;
|
private volatile boolean outputShutdown;
|
||||||
|
|
||||||
|
@ -82,18 +83,19 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SocketAddress localAddress0() {
|
protected SocketAddress localAddress0() {
|
||||||
return Native.localAddress(fd);
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SocketAddress remoteAddress0() {
|
protected SocketAddress remoteAddress0() {
|
||||||
return Native.remoteAddress(fd);
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doBind(SocketAddress local) throws Exception {
|
protected void doBind(SocketAddress local) throws Exception {
|
||||||
InetSocketAddress localAddress = (InetSocketAddress) local;
|
InetSocketAddress localAddress = (InetSocketAddress) local;
|
||||||
Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
|
Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
|
||||||
|
this.local = Native.localAddress(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEpollOut() {
|
private void setEpollOut() {
|
||||||
|
@ -538,6 +540,8 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
||||||
checkResolvable(remoteAddress);
|
checkResolvable(remoteAddress);
|
||||||
boolean connected = Native.connect(fd, remoteAddress.getAddress(),
|
boolean connected = Native.connect(fd, remoteAddress.getAddress(),
|
||||||
remoteAddress.getPort());
|
remoteAddress.getPort());
|
||||||
|
remote = remoteAddress;
|
||||||
|
local = Native.localAddress(fd);
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
setEpollOut();
|
setEpollOut();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user