cURL / Mailing Lists / curl-library / Single Mail

curl-library

Performance problem II

From: Stefan Sassenberg <stefan.sassenberg_at_gmx.de>
Date: Tue, 25 Nov 2003 09:32:13 +0100

Hello everybody,

maybe you remember my performance problem? It had several reasons most
of which I could eliminate with your help.

Now there's one big problem left which is the data transfer itself. The
transfer of a file (70kByte) using the windows command line tool 'ftp'
takes about 80-90ms. With libcurl it takes about 450ms. The network
analyzer tells me that there are gaps between the packets from time to
time with a size of about 80ms. Can you help me finding the reason for
this? My sending method and the callback function are listed below.

Stefan

extern "C"
{
    size_t readFunction(void* ptr, size_t size, size_t nmemb, void* stream)
    {
        return fread(ptr, size, nmemb, (FILE*)stream);
    }
}

void FtpPort::send(std::string& rUploadFile)
{
    //std::cout << "FtpPort::send(" << rUploadFile << ")" << std::endl;
    const char* fileName = rUploadFile.c_str();
    FILE* hd_src = fopen(rUploadFile.c_str(), "rb");
   
    std::string renameFrom = ("RNFR (nil)");
    std::string renameTo = ("RNTO " +
rUploadFile.substr(rUploadFile.find_last_of("\\") + 1));

// get the file size of the local file
    struct stat fileInfo;
    stat(rUploadFile.c_str(),&fileInfo);

    // prepare for an upload
    curl_easy_setopt(mCurl, CURLOPT_UPLOAD, TRUE);

    // build a list of commands to pass to libcurl
    struct curl_slist* headerlist = NULL;
    headerlist = curl_slist_append(headerlist, renameFrom.c_str());
    headerlist = curl_slist_append(headerlist, renameTo.c_str());
    // pass in that last of FTP commands to run after the transfer
    curl_easy_setopt(mCurl, CURLOPT_POSTQUOTE, headerlist);

    // now specify which file to upload
    curl_easy_setopt(mCurl, CURLOPT_INFILE, hd_src);

    // and give the size of the upload (optional)
    curl_easy_setopt(mCurl, CURLOPT_INFILESIZE, fileInfo.st_size);

    // READFUNCTION must be given when INFILE is used
    curl_easy_setopt(mCurl, CURLOPT_READFUNCTION, readFunction);

    CURLcode result = curl_easy_perform(mCurl);
    if (result) {
        std::cout << "FtpPort::send: curl error: " << arErrorMessage <<
std::endl;
    }

    // clean up headerlist
    curl_slist_free_all( headerlist );

    fclose(hd_src);
}

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-25