コード例 #1
0
ファイル: s_time.c プロジェクト: Adallom/openssl
/*-
 * doConnection - make a connection
 * Args:
 *              scon    = earlier ssl connection for session id, or NULL
 * Returns:
 *              SSL *   = the connection pointer.
 */
static SSL *doConnection(SSL *scon)
{
    BIO *conn;
    SSL *serverCon;
    int width, i;
    fd_set readfds;

    if ((conn = BIO_new(BIO_s_connect())) == NULL)
        return (NULL);

/*      BIO_set_conn_port(conn,port);*/
    BIO_set_conn_hostname(conn, host);

    if (scon == NULL)
        serverCon = SSL_new(tm_ctx);
    else {
        serverCon = scon;
        SSL_set_connect_state(serverCon);
    }

    SSL_set_bio(serverCon, conn, conn);

    /* ok, lets connect */
    for (;;) {
        i = SSL_connect(serverCon);
        if (BIO_sock_should_retry(i)) {
            BIO_printf(bio_err, "DELAY\n");

            i = SSL_get_fd(serverCon);
            width = i + 1;
            FD_ZERO(&readfds);
            openssl_fdset(i, &readfds);
            /*
             * Note: under VMS with SOCKETSHR the 2nd parameter is currently
             * of type (int *) whereas under other systems it is (void *) if
             * you don't have a cast it will choke the compiler: if you do
             * have a cast then you can either go for (int *) or (void *).
             */
            select(width, (void *)&readfds, NULL, NULL, NULL);
            continue;
        }
        break;
    }
    if (i <= 0) {
        BIO_printf(bio_err, "ERROR\n");
        if (verify_error != X509_V_OK)
            BIO_printf(bio_err, "verify error:%s\n",
                       X509_verify_cert_error_string(verify_error));
        else
            ERR_print_errors(bio_err);
        if (scon == NULL)
            SSL_free(serverCon);
        return NULL;
    }

    return serverCon;
}
コード例 #2
0
ファイル: asynctest.c プロジェクト: erbridge/openssl
static int hasdata(OSSL_ASYNC_FD fd)
{
#ifdef ASYNC_POSIX
    fd_set checkfds;
    struct timeval tv;
    FD_ZERO(&checkfds);
    openssl_fdset(fd, &checkfds);
    memset(&tv, 0, sizeof tv);
    if (select(fd + 1, (void *)&checkfds, NULL, NULL, &tv) < 0)
        return -1;
    if (FD_ISSET(fd, &checkfds))
        return 1;
    return 0;
#else
    DWORD avail = 0;

    if (PeekNamedPipe(fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
        return 1;

    return 0;
#endif
}