Ravi Kasibhatla <kasibhatla.ravi <at> gmail.com> writes:

> 
> 
> Hi,
> I am attaching a sample program I have written to show usage of the 
curl_easy_pause() API in my code. This sample program is not working as 
expected. Please let me know if the usage of the API in my program is correct 
or 
wrong. 
> 
> The current output of the program is below:
> ---- paused the curl handle for perform 
> ---- added the timer for 1sec 
> ---- came to curl header callback 
> ---- came to curl callback with data: 
> 
> ---- added the timer for 1sec again
> ---- added the timer for 1sec again
> ---- added the timer for 1sec again
> ---- continued the curl handle for perform 
> 
> 
> 
> The output that I am looking for should be something like below:
> 
> ---- paused the curl handle for perform 
> ---- added the timer for 1sec 
> ---- added the timer for 1sec again
> 
> ---- added the timer for 1sec again
> ---- added the timer for 1sec again
> ---- continued the curl handle for perform 
> 
> ---- came to curl header callback 
> 
> ---- came to curl callback with data: 
> 
> 
> Thanks in advance,
> Ravi
> 
> 
> 
> On Thu, Oct 15, 2009 at 1:14 PM, Ravi Kasibhatla <kasibhatla.ravi <at> 
gmail.com> wrote:Thanks Daniel for the clarification.
> In that scenario, the curl behavior in my code is not correct, because for me 
the callbacks are getting called even when the curl handle is in paused state. 
Can somebody point to me any example/test case, which shows how to use the api 
curl_easy_pause()? I searched for the example but couldn't find any.
> 
> 
> 
> I am using the latest curl release i.e. 7.19.5 for my testing. I have also 
tested the same scenario with curl release 7.18.2.
> 
> Thanks in advance,
> Ravi
> 
> 
> 
> 
> On Wed, Oct 14, 2009 at 8:31 AM, Daniel Stenberg <daniel <at> haxx.se> wrote:
> 
> 
> On Wed, 7 Oct 2009, Ravi Kasibhatla wrote:
> I have a query regarding the usage of the function curl_easy_pause(). In my 
code, I have defined all the 3 curl callbacks i.e. header, write & read. For 
some condition I am calling curl_easy_pause() with CURLPAUSE_ALL mask value for 
a curl handle. After that also, I see the invocation of header callback by curl 
for that curl handle. Is this the expected behavior?
> 
> 
> 
> No.
> 
> From the given documentation, I came to the understanding that the API would 
just stop the calling of the read & write callbacks only (based on the mask 
value set). The curl header callback would be called irrespective of whether 
the 
curl handle is in paused state or not.
> 
> 
> 
> No, the header callback is just a special write callback so a paused transfer 
shouldn't call that either.
> 

Please can anybody check the attached program (pasted below) and let me know 
whether my usage of curl api curl_easy_pause() is correct or not. If it is 
wrong, please tell me how to use it correctly. I didn't found any 
documentation/sample which gave it's usage.

Thanks in advance,
Ravi

The sample program:

#include <curl/curl.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>

enum {
    HEADER,
    WRITE,
    READ
};
struct __data {
    int timeout_count;
    int callback_type;
    char function_name[128];
};
typedef struct __data data_t;

static CURL *hnd;
static data_t timer_data, hdr_cb, write_cb, read_cb;

static gboolean pause_timeoutadd(gpointer data)
{
    data_t* timerdata = (data_t*)data;
    if(timerdata->timeout_count < 4) {
        timerdata->timeout_count++;
        g_timeout_add(1000, pause_timeoutadd, (gpointer)timerdata);
        printf("---- added the timer for 1sec again\n");
    }
    else {
        curl_easy_pause(hnd, CURLPAUSE_CONT);
        printf("---- continued the curl handle for perform \n");
  //curl_easy_perform(hnd);
    }
    return FALSE;
}

static size_t curl_headercallback( void *ptr, size_t size, size_t nmemb, void 
*stream)
{
    data_t *data = (data_t *)stream;
    printf("---- came to curl header callback \n");
    //printf("---- came to curl callback with data: \n timer_count: %d\n 
callback type: %d\n function_name: %s\n", 
    //        data->timeout_count, data->callback_type, data->function_name);
    return size*nmemb;
}

static size_t curl_writecallback( void *ptr, size_t size, size_t nmemb, void 
*stream)
{
    data_t *data = (data_t *)stream;
    printf("---- came to curl callback with data: \n timer_count: %d\n callback 
type: %d\n function_name: %s\n",
            data->timeout_count, data->callback_type, data->function_name);
    return size*nmemb;
}

static size_t curl_readcallback( void *ptr, size_t size, size_t nmemb, void 
*stream)
{
    data_t *data = (data_t *)stream;
    printf("---- came to curl callback with data: \n timer_count: %d\n callback 
type: %d\n function_name: %s\n",
            data->timeout_count, data->callback_type, data->function_name);
    return size*nmemb;
}

int main(int argc, char *argv[])
{
  CURLcode ret;
  hnd = curl_easy_init();
  gtk_init(&argc, &argv);

  memset(&hdr_cb, 0, sizeof(data_t));
  hdr_cb.callback_type = HEADER;
  strcpy(hdr_cb.function_name, "curl_headercallback");
  curl_easy_setopt(hnd, CURLOPT_WRITEHEADER, &hdr_cb);
  curl_easy_setopt(hnd, CURLOPT_HEADERFUNCTION, curl_headercallback);

  memset(&write_cb, 0, sizeof(data_t));
  write_cb.callback_type = WRITE;
  strcpy(write_cb.function_name, "curl_writecallback");
  curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &write_cb);
  curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, curl_writecallback);

  memset(&read_cb, 0, sizeof(data_t));
  read_cb.callback_type = READ;
  strcpy(read_cb.function_name, "curl_readcallback");
  curl_easy_setopt(hnd, CURLOPT_READDATA, &read_cb);
  curl_easy_setopt(hnd, CURLOPT_READFUNCTION, curl_readcallback);

  curl_easy_setopt(hnd, CURLOPT_INFILESIZE_LARGE, (curl_off_t)-1);
  curl_easy_setopt(hnd, CURLOPT_URL, "www.rediff.com");
  curl_easy_setopt(hnd, CURLOPT_PROXY, "172.17.1.16:8080");
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1);
  curl_easy_setopt(hnd, CURLOPT_HEADER, 0);
  curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 0);
  curl_easy_setopt(hnd, CURLOPT_UPLOAD, 0);
  curl_easy_setopt(hnd, CURLOPT_DIRLISTONLY, 0);
  curl_easy_setopt(hnd, CURLOPT_APPEND, 0);
  curl_easy_setopt(hnd, CURLOPT_NETRC, 0);
  curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 0);
  curl_easy_setopt(hnd, CURLOPT_UNRESTRICTED_AUTH, 0);
  curl_easy_setopt(hnd, CURLOPT_TRANSFERTEXT, 0);
  curl_easy_setopt(hnd, CURLOPT_USERPWD, NULL);
  curl_easy_setopt(hnd, CURLOPT_PROXYUSERPWD, NULL);
  curl_easy_setopt(hnd, CURLOPT_NOPROXY, NULL);
  curl_easy_setopt(hnd, CURLOPT_RANGE, NULL);
  curl_easy_setopt(hnd, CURLOPT_TIMEOUT, 0);
  curl_easy_setopt(hnd, CURLOPT_REFERER, NULL);
  curl_easy_setopt(hnd, CURLOPT_AUTOREFERER, 0);
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.19.6 (i686-pc-linux-gnu) 
libcurl/7.19.6 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1");
  curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_LIMIT, 0);
  curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_TIME, 0);
  curl_easy_setopt(hnd, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t)0);
  curl_easy_setopt(hnd, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)0);
  curl_easy_setopt(hnd, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)0);
  curl_easy_setopt(hnd, CURLOPT_COOKIE, NULL);
  curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, NULL);
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50);
  curl_easy_setopt(hnd, CURLOPT_CRLF, 0);
  curl_easy_setopt(hnd, CURLOPT_QUOTE, NULL);
  curl_easy_setopt(hnd, CURLOPT_POSTQUOTE, NULL);
  curl_easy_setopt(hnd, CURLOPT_PREQUOTE, NULL);
  curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, NULL);
  curl_easy_setopt(hnd, CURLOPT_COOKIESESSION, 0);
  curl_easy_setopt(hnd, CURLOPT_TIMECONDITION, 0);
  curl_easy_setopt(hnd, CURLOPT_TIMEVALUE, 0);
  curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, NULL);
  curl_easy_setopt(hnd, CURLOPT_INTERFACE, NULL);
  curl_easy_setopt(hnd, CURLOPT_EGDSOCKET, NULL);
  curl_easy_setopt(hnd, CURLOPT_CONNECTTIMEOUT, 0);
  curl_easy_setopt(hnd, CURLOPT_ENCODING, NULL);
  curl_easy_setopt(hnd, CURLOPT_IPRESOLVE, 0);
  curl_easy_setopt(hnd, CURLOPT_IGNORE_CONTENT_LENGTH, 0);
  curl_easy_setopt(hnd, CURLOPT_POSTREDIR, 0);

  ret = curl_easy_pause(hnd, CURLPAUSE_ALL);
  printf("---- paused the curl handle for perform \n");
  if(ret == CURLE_OK) {
      memset(&timer_data, 0, sizeof(data_t));
      timer_data.timeout_count = 1;
      g_timeout_add(1000, pause_timeoutadd, &timer_data);
      printf("---- added the timer for 1sec \n");
  }
  ret = curl_easy_perform(hnd);

  gtk_main();
  curl_easy_cleanup(hnd);
  return (int)ret;
}



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

Reply via email to