doc/designs/ddd/ddd-05-mem-nonblocking.c
/*
 * The application wants to create a new outgoing connection using a given
 * SSL_CTX.
 *
 * hostname is a string like "openssl.org" used for certificate validation.
 */
The application wants to create a new outgoing connection using a given
SSL_CTX.

hostname is a string like "openssl.org" used for certificate validation.
The application wants to create a new outgoing connection using a given SSL_CTX . hostname is a string like " openssl . org " used for certificate validation .
APP_CONN *new_conn(SSL_CTX *ctx, const char *bare_hostname)
{
    BIO *ssl_bio, *internal_bio, *net_bio;
    APP_CONN *conn;
    SSL *ssl;
    conn = calloc(1, sizeof(APP_CONN));
    if (conn == NULL)
        return NULL;
    ssl = conn->ssl = SSL_new(ctx);
    if (ssl == NULL) {
        free(conn);
        return NULL;
    }
    SSL_set_connect_state(ssl); 
    if (BIO_new_bio_pair(&internal_bio, 0, &net_bio, 0) <= 0) {
        SSL_free(ssl);
        free(conn);
        return NULL;
    }
    SSL_set_bio(ssl, internal_bio, internal_bio);
    if (SSL_set1_host(ssl, bare_hostname) <= 0) {
        SSL_free(ssl);
        free(conn);
        return NULL;
    }
    if (SSL_set_tlsext_host_name(ssl, bare_hostname) <= 0) {
        SSL_free(ssl);
        free(conn);
        return NULL;
    }
    ssl_bio = BIO_new(BIO_f_ssl());
    if (ssl_bio == NULL) {
        SSL_free(ssl);
        free(conn);
        return NULL;
    }
    if (BIO_set_ssl(ssl_bio, ssl, BIO_CLOSE) <= 0) {
        SSL_free(ssl);
        BIO_free(ssl_bio);
        return NULL;
    }
    conn->ssl_bio   = ssl_bio;
    conn->net_bio   = net_bio;
    return conn;
}
APP_CONN * new_conn ( SSL_CTX * ctx , const char * bare_hostname ) { BIO * ssl_bio , * internal_bio , * net_bio ; APP_CONN * conn ; SSL * ssl ; conn = calloc ( 1 , sizeof ( APP_CONN ) ) ; if ( conn == NULL ) return NULL ; ssl = conn -> ssl = SSL_new ( ctx ) ; if ( ssl == NULL ) { free ( conn ) ; return NULL ; } SSL_set_connect_state ( ssl ) ; if ( BIO_new_bio_pair ( & internal_bio , 0 , & net_bio , 0 ) <= 0 ) { SSL_free ( ssl ) ; free ( conn ) ; return NULL ; } SSL_set_bio ( ssl , internal_bio , internal_bio ) ; if ( SSL_set1_host ( ssl , bare_hostname ) <= 0 ) { SSL_free ( ssl ) ; free ( conn ) ; return NULL ; } if ( SSL_set_tlsext_host_name ( ssl , bare_hostname ) <= 0 ) { SSL_free ( ssl ) ; free ( conn ) ; return NULL ; } ssl_bio = BIO_new ( BIO_f_ssl ( ) ) ; if ( ssl_bio == NULL ) { SSL_free ( ssl ) ; free ( conn ) ; return NULL ; } if ( BIO_set_ssl ( ssl_bio , ssl , BIO_CLOSE ) <= 0 ) { SSL_free ( ssl ) ; BIO_free ( ssl_bio ) ; return NULL ; } conn -> ssl_bio = ssl_bio ; conn -> net_bio = net_bio ; return conn ; }
The application wants to create a new outgoing connection using a given
 SSL_CTX.
The application wants to create a new outgoing connection using a given SSL_CTX .
/* cannot fail */