curl-library
Re: AIX multithreaded problem in CURLE_SSL_CONNECT_ERROR,why?
Date: Mon, 15 Nov 2004 17:55:27 +0800
----- Original Message -----
From: "Daniel Stenberg" <daniel-curl_at_haxx.se>
To: "libcurl development" <curl-library_at_cool.haxx.se>
Sent: Monday, November 15, 2004 5:14 PM
Subject: Re: AIX multithreaded problem in CURLE_SSL_CONNECT_ERROR,why?
> On Mon, 15 Nov 2004, hzhijun wrote:
>
> > In my multithread program, the Get/Post without SSL works fine. But if I
> > post a request to a web server with ssl(like:
> > https://10.77.107.111/index.htm), it always returns "SSL connect error"
>
> Have you set the OpenSSL multithread-callbacks for locking etc?
>
Below is the test program, and i only find the problem in aix 4.3(in sun,hp, linux platform, it works fine)
/*****************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* $Id: multithread.c,v 1.1 2001/05/04 09:35:43 bagder Exp $
*/
/* A multi-threaded example that uses pthreads extensively to fetch
* X remote files at once */
#include <stdio.h>
#include <pthread.h>
#include <curl/curl.h>
/* silly list of test-URLs */
char *urls[]= {
"https://10.71.115.46/ackget.php",
"https://10.71.115.46/ackget.php",
"https://10.71.115.46/ackget.php",
"https://10.71.115.46/ackget.php",
};
void *pull_one_url(void *url)
{
CURLcode curlRet;
const char *pCertFile = "www.infosecurity.org.cn_Cert.crt";
const char *pKeyName;
const char *pKeyType;
const char *pEngine;
const char *pPassphrase = "infosecurity";
CURL *curl = NULL ;
pKeyName = "www.infosecurity.org.cn_Key.pem";
pKeyType = "PEM";
pEngine = NULL;
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
if (curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM") != CURLE_OK)
{
printf("CURLOPT_SSLCERTTYPE failed\n");
}
/* set the cert for client authentication */
if (curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile) != CURLE_OK)
{
printf("CURLOPT_SSLCERT failed\n");
}
/* sorry, for engine we must set the passphrase
(if the key has one...) */
if (pPassphrase)
{
printf("pPassphrase is not NULL!\n");
curl_easy_setopt(curl,CURLOPT_SSLKEYPASSWD,pPassphrase);
}
/* if we use a key stored in a crypto engine,
we must set the key type to "ENG" */
if (curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType) != CURLE_OK)
{
printf("CURLOPT_SSLKEYTYPE failed\n");
}
/* set the private key (file or ID in engine) */
if (curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName) != CURLE_OK)
{
printf("CURLOPT_SSLKEY failed\n");
}
/* set the file with the certs vaildating the server */
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,0);
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST, 1);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curlRet = curl_easy_perform(curl);
printf("\ncurl_easy_perform return %d\n", curlRet );
printf("\ncurlRet meaning: %s\n", curl_easy_strerror(curlRet) );
curl_easy_cleanup(curl);
return NULL;
}
/*
int pthread_create(pthread_t *new_thread_ID,
const pthread_attr_t *attr,
void * (*start_func)(void *), void *arg);
*/
int main(int argc, char **argv)
{
pthread_t tid[4];
int i;
int error;
for(i=0; i< 4; i++) {
error = pthread_create(&tid[i],
NULL, /* default attributes please */
pull_one_url,
urls[i]);
if(0 != error)
fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
else
fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
}
/* now wait for all threads to terminate */
for(i=0; i< 4; i++) {
error = pthread_join(tid[i], NULL);
fprintf(stderr, "Thread %d terminated\n", i);
}
return 0;
}
Received on 2004-11-15