Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@ public ByteChannel channel() {

@Override
public SocketAddress getLocalAddress() {
return this.channel.socket().getLocalSocketAddress();
try {
return this.channel.getLocalAddress();
} catch (final IOException e) {
return null;
}
}

@Override
public SocketAddress getRemoteAddress() {
return this.channel.socket().getRemoteSocketAddress();
try {
return channel.getRemoteAddress();
} catch (final IOException e) {
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.net.UnknownHostException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
Expand Down Expand Up @@ -277,21 +278,26 @@ public Future<IOSession> connect(
}

private void prepareSocket(final SocketChannel socketChannel) throws IOException {
final Socket socket = socketChannel.socket();
socket.setTcpNoDelay(this.reactorConfig.isTcpNoDelay());
socket.setKeepAlive(this.reactorConfig.isSoKeepAlive());
if (this.reactorConfig.getSndBufSize() > 0) {
socket.setSendBufferSize(this.reactorConfig.getSndBufSize());
socketChannel.setOption(StandardSocketOptions.SO_SNDBUF, this.reactorConfig.getSndBufSize());
}
if (this.reactorConfig.getRcvBufSize() > 0) {
socket.setReceiveBufferSize(this.reactorConfig.getRcvBufSize());
}
if (this.reactorConfig.getTrafficClass() > 0) {
socket.setTrafficClass(this.reactorConfig.getTrafficClass());
socketChannel.setOption(StandardSocketOptions.SO_RCVBUF, this.reactorConfig.getRcvBufSize());
}
final int linger = this.reactorConfig.getSoLinger().toSecondsIntBound();
if (linger >= 0) {
socket.setSoLinger(true, linger);
socketChannel.setOption(StandardSocketOptions.SO_LINGER, linger);
}

// None of the below options are applicable to Unix domain sockets.
if (!(socketChannel.getRemoteAddress() instanceof InetSocketAddress)) {
return;
}
socketChannel.setOption(StandardSocketOptions.TCP_NODELAY, this.reactorConfig.isTcpNoDelay());
socketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, this.reactorConfig.isSoKeepAlive());

if (this.reactorConfig.getTrafficClass() > 0) {
socketChannel.setOption(StandardSocketOptions.IP_TOS, this.reactorConfig.getTrafficClass());
}
if (this.reactorConfig.getTcpKeepIdle() > 0) {
setExtendedSocketOption(socketChannel, SocketSupport.TCP_KEEPIDLE, this.reactorConfig.getTcpKeepIdle());
Expand Down