public static final SocketChannel setSocketOptions(ClickHouseConfig config, SocketChannel socket)
            throws IOException {
        if (socket == null || socket.socket().isClosed()) {
            throw new IllegalArgumentException("Cannot set option(s) on a null or closed socket channel");
        } else if (config == null) {
            return socket;
        }

        if (config.hasOption(ClickHouseClientOption.SOCKET_IP_TOS)) {
            socket.setOption(StandardSocketOptions.IP_TOS, config.getIntOption(ClickHouseClientOption.SOCKET_IP_TOS));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_KEEPALIVE)) {
            socket.setOption(StandardSocketOptions.SO_KEEPALIVE,
                    config.getBoolOption(ClickHouseClientOption.SOCKET_KEEPALIVE));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_LINGER)) {
            socket.setOption(StandardSocketOptions.SO_LINGER,
                    config.getIntOption(ClickHouseClientOption.SOCKET_LINGER));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_REUSEADDR)) {
            socket.setOption(StandardSocketOptions.SO_REUSEADDR,
                    config.getBoolOption(ClickHouseClientOption.SOCKET_REUSEADDR));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_RCVBUF)) {
            int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_RCVBUF);
            socket.setOption(StandardSocketOptions.SO_RCVBUF, bufferSize > 0 ? bufferSize : config.getReadBufferSize());
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_SNDBUF)) {
            int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_SNDBUF);
            socket.setOption(StandardSocketOptions.SO_SNDBUF,
                    bufferSize > 0 ? bufferSize : config.getWriteBufferSize());
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_TCP_NODELAY)) {
            socket.setOption(StandardSocketOptions.TCP_NODELAY,
                    config.getBoolOption(ClickHouseClientOption.SOCKET_TCP_NODELAY));
        }
        return socket;
    }
Sets socket options. May be called at any time(e.g. before or even after the
socket is bound or connected).

@param config non-null configuration
@param socket non-null socket channel
@return the given socket channel
@throws IOException when there's error setting socket options
clickhouse-client/src/main/java/com/clickhouse/client/AbstractSocketClient.java