cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Need urgent help to find the flaw in this use of libcurl

From: amit paliwal <amit.ambitions_at_gmail.com>
Date: Wed, 29 Dec 2010 19:37:03 -0500

In case the attachment does not work, I am pasting the code also:

void *SessionThread(void *parm)
{

      CURL *ctx;
    CURLcode res;
    int sockfd; /* socket */
    size_t iolen;

    curl_global_init( CURL_GLOBAL_ALL ) ;
    ctx = curl_easy_init() ;
    if( NULL == ctx )
    {
    }

    curl_easy_setopt( ctx , CURLOPT_URL, "http://localhost:4433" ) ;
    curl_easy_setopt( ctx , CURLOPT_INTERFACE, "127.0.0.1" ) ;
    curl_easy_setopt( ctx , CURLOPT_LOCALPORT, 4434 );
    curl_easy_setopt(ctx, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_easy_setopt( ctx , CURLOPT_WRITEDATA ,ctx);
    curl_easy_setopt( ctx , CURLOPT_WRITEFUNCTION , write_data );
    curl_easy_setopt(ctx, CURLOPT_HEADERFUNCTION, headercb);

    res = curl_easy_perform(ctx);
    if(CURLE_OK != res)
    {
        printf("\nError: %d::%s\n", res,strerror(res));
        }

}

size_t write_data( void *buffer, size_t size, size_t nmemb, void *userp )
{
  int segsize = size * nmemb;

  CURL *ctx = (CURL*)userp;
  printf("\nCurl object address is:%p",ctx);
  CURLcode ret;

  curl_easy_setopt( ctx1 , CURLOPT_READDATA ,ctx);
  curl_easy_setopt( ctx1 , CURLOPT_READFUNCTION , readcb );
  curl_easy_setopt(ctx1, CURLOPT_CUSTOMREQUEST, "GET") ;
  int ret = curl_easy_perform(ctx1);
  if(CURLE_OK != ret)
  {
  }
  return segsize;
}

size_t readcb(void *ptr, size_t size, size_t nitems, void *stream)
{
    printf("\nEntered inside read callback");

    int len = size * nitems;
    return len;
}

size_t headercb(void *ptr, size_t size, size_t nmemb, void *buffer)
{
    printf("\nInside Header");
    int ret = size*nmemb;

    return ret;
}

On Wed, Dec 29, 2010 at 7:34 PM, amit paliwal <amit.ambitions_at_gmail.com>wrote:

> Hi,
>
> Please refer to the code i have attached, and help me finding the flaw.
> Once I receive HTTP response message, I Prepare another GET message in write
> callback and I expect my read callback to be called for custom data.
>
> What am I doing wrong in it?
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-12-30