curl-library
libcurl win32 multi-thread problem
Date: Tue, 19 Sep 2006 17:30:09 +0300
Hello people !
I have an multi threaded application that must upload from each thread a
file to an ftp server.
The problem is that only one thread is uploading and the speed never reaches
60kb/s in the same LAN.
here is the function called from each thread:
int ftp_upload(char* username, char* password, char* address, char*
remote_dir, char* local_file, char* upload_as )
{
FILE * hd_src ;
CURL* curl_handler;
CURLcode res;
char* REMOTE_URL;
int hd ;
struct stat file_info;
char* buf_1; //[] = "RNFR " UPLOAD_FILE_AS;
char* buf_2; //[] = "RNTO " RENAME_FILE_TO;
curl_global_init(CURL_GLOBAL_ALL);
curl_handler = curl_easy_init();
curl_easy_setopt(curl_handler, CURLOPT_NOSIGNAL, TRUE) ;
hd = open(local_file, O_RDONLY) ;
fstat(hd, &file_info);
close(hd) ;
hd_src = fopen(local_file, "rb");
buf_1=(char*)malloc(strlen("RNFR .temp")+strlen(upload_as));
buf_2=(char*)malloc(strlen(upload_as)+10);
sprintf(buf_1,"RNFR %s.temp",upload_as);
sprintf(buf_2,"RNTO %s.xxx",upload_as);
curl_easy_setopt(curl_handler, CURLOPT_UPLOAD, TRUE) ;
REMOTE_URL=(char*)malloc(strlen(username)+strlen(password)+strlen(address)+strlen(remote_dir)+strlen(upload_as)+11);
sprintf(REMOTE_URL,"
ftp://%s:%s@%s/%s/%s",username,password,address,remote_dir,upload_as);
curl_easy_setopt(curl_handler,CURLOPT_URL, REMOTE_URL);
curl_easy_setopt(curl_handler, CURLOPT_READDATA, hd_src);
curl_easy_setopt(curl_handler,
CURLOPT_INFILESIZE_LARGE,(curl_off_t)file_info.st_size);
res = curl_easy_perform(curl_handler);
curl_easy_cleanup(curl_handler);
curl_global_cleanup();
fclose(hd_src); /* close the local file */
return res;
}
thanks !
-- Respect RazvanReceived on 2006-09-19