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

        if (!socket.isConnected() || !socket.isBound()) {
            socket.setSoTimeout(config.getSocketTimeout());
        } else if (config.hasOption(ClickHouseClientOption.SOCKET_TIMEOUT)) {
            socket.setSoTimeout(config.getIntOption(ClickHouseClientOption.SOCKET_TIMEOUT));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_IP_TOS)) {
            socket.setTrafficClass(config.getIntOption(ClickHouseClientOption.SOCKET_IP_TOS));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_KEEPALIVE)) {
            socket.setKeepAlive(config.getBoolOption(ClickHouseClientOption.SOCKET_KEEPALIVE));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_LINGER)) {
            int solinger = config.getIntOption(ClickHouseClientOption.SOCKET_LINGER);
            socket.setSoLinger(solinger >= 0, solinger);
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_REUSEADDR)) {
            socket.setReuseAddress(config.getBoolOption(ClickHouseClientOption.SOCKET_REUSEADDR));
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_RCVBUF)) {
            int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_RCVBUF);
            socket.setReceiveBufferSize(bufferSize > 0 ? bufferSize : config.getReadBufferSize());
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_SNDBUF)) {
            int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_SNDBUF);
            socket.setSendBufferSize(bufferSize > 0 ? bufferSize : config.getWriteBufferSize());
        }
        if (config.hasOption(ClickHouseClientOption.SOCKET_TCP_NODELAY)) {
            socket.setTcpNoDelay(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
@return the given socket
@throws SocketException when there's error setting socket options
clickhouse-client/src/main/java/com/clickhouse/client/AbstractSocketClient.java