NOEXPORT void session_cache_retrieve(CLI *c) {
    SSL_SESSION *sess;

    CRYPTO_THREAD_read_lock(stunnel_locks[LOCK_SESSION]);
    if(c->opt->option.delayed_lookup) {
        sess=c->opt->session;
    } else { /* per-destination client cache */
        if(c->opt->connect_session) {
            sess=c->opt->connect_session[c->idx];
        } else {
            s_log(LOG_ERR, "INTERNAL ERROR: Uninitialized client session cache");
            sess=NULL;
        }
    }
    if(sess)
        SSL_set_session(c->ssl, sess);
    CRYPTO_THREAD_unlock(stunnel_locks[LOCK_SESSION]);
}
NOEXPORT void session_cache_retrieve(CLI *c) {
    SSL_SESSION *sess;

    CRYPTO_THREAD_read_lock(stunnel_locks[LOCK_SESSION]);
    if(c->opt->option.delayed_lookup) {
        sess=c->opt->session;
    } else {  
        if(c->opt->connect_session) {
            sess=c->opt->connect_session[c->idx];
        } else {
            s_log(LOG_ERR, "INTERNAL ERROR: Uninitialized client session cache");
            sess=NULL;
        }
    }
    if(sess)
        SSL_set_session(c->ssl, sess);
    CRYPTO_THREAD_unlock(stunnel_locks[LOCK_SESSION]);
}