cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Use of multi interface of libcurl

From: amit paliwal <amit.ambitions_at_gmail.com>
Date: Thu, 30 Dec 2010 09:47:39 -0500

On Thu, Dec 30, 2010 at 7:38 AM, Dirk Manske <dm_at_nonitor.de> wrote:

> > If I need to do repeated transactions of GET and RESPONSE do I need to
> use
> > multi interface rather than easy interface?
> No. You only need the multi interface if you doing requests
> in parallel (and if you don't what to use threads).
> For step-by-step transactions the easy interface fits perfectly.
>
> Please refer to below sample code as it is not working for me, please help
me find problem in it. I posted it in another thread also but not gettign
any response and it is very imp for me:

In the code below I am not able to let my read callback called for another
GET, I think we can send soem custom data with GET right?

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;
}

> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>

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