return createSocketChannel(sockAddr, blocking, soRcvBufSize);
}
}
private static SocketChannel createSocketChannel(final SocketAddress sockAddr, final boolean blocking, final int rcvbufSize) {
final SocketChannel ch;
try {
ch = SocketChannel.open();
ch.configureBlocking(blocking);
} catch (IOException e) {
LOG.error("Failed to open SocketChannel.", e);
throw new IllegalStateException(e);
}
final Socket sock = ch.socket();
if(rcvbufSize != -1) {
try {
sock.setReceiveBufferSize(rcvbufSize);
} catch (SocketException e) {
LOG.error("Failed to setReceiveBufferSize.", e);
throw new IllegalStateException(e);
}
}
final boolean connected;
try {
connected = ch.connect(sockAddr);
} catch (IOException e) {
LOG.error("Failed to connect socket: " + sockAddr, e);
throw new IllegalStateException(e);
}
if(!connected) {