title: operation was aborted by an application callback - libcurl
body: <p>I have the following libcurl program. When I run the program I get the following error.</p>
  
  <pre><code>Operation was aborted by an application callback
  
  Process finished with exit code 42
  </code></pre>
  
  <p>My complete program</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;curl/curl.h&gt;
  #include &lt;cstdint&gt;
  #include &lt;malloc.h&gt;
  #include &lt;cstring&gt;
  
  #define TIMETYPE double
  #define TIMEOPT CURLINFO_TOTAL_TIME
  
  #define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES         6000
  
  struct myprogress {
      TIMETYPE lastruntime; 
      CURL *curl;
  };
  
  struct memoryStruct {
      uint8_t* memory;
      size_t size;
  };
  
  size_t handleData(void* contents, size_t size, size_t nmemb, void* stream) {
      size_t realSize = size * nmemb;
      struct memoryStruct* mem = static_cast&lt;struct memoryStruct*&gt;(stream);
  
      mem-&gt;memory = static_cast&lt;uint8_t*&gt;(realloc(mem-&gt;memory, (mem-&gt;size + realSize + 1)));
      if (mem-&gt;memory == nullptr) {
          return 0;
      }
      memcpy(&amp;(mem-&gt;memory[mem-&gt;size]), contents, realSize);
      mem-&gt;size += realSize;
      mem-&gt;memory[mem-&gt;size] = 0;
  
      return realSize;
  }
  
  static int xferinfo(void *p,
                      curl_off_t dltotal, curl_off_t dlnow,
                      curl_off_t ultotal, curl_off_t ulnow)
  {
      struct myprogress *myp = (struct myprogress *)p;
      CURL *curl = myp-&gt;curl;
      TIMETYPE curtime = 0;
  
      curl_easy_getinfo(curl, TIMEOPT, &amp;curtime);
  
      myp-&gt;lastruntime = curtime;
      fprintf(stderr, "TOTAL TIME: %f \r\n", curtime);
  
      fprintf(stderr,"  DOWN: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
                      "\r\n", dlnow, dltotal);
  
      if(dlnow &gt; STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES)
          return 1;
      return 0;
  }
  
  int main(void)
  {
      CURL *curl;
      CURLcode res = CURLE_OK;
      struct myprogress prog;
      struct memoryStruct m_chunk;
  
      curl = curl_easy_init();
      if(curl) {
          prog.lastruntime = 0;
          prog.curl = curl;
  
          m_chunk.memory = static_cast&lt;uint8_t*&gt;(malloc(1));
          if (nullptr == m_chunk.memory) {
              return 1;
          }
          m_chunk.size = 0;
  
  
          curl_easy_setopt(curl, CURLOPT_URL, "http://172.16.132.84:5000/download/file.out");
  
          curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handleData);
  
          curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) &amp;m_chunk);
  
          curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo);
  
          curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &amp;prog);
  
          curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
          res = curl_easy_perform(curl);
  
          if(res != CURLE_OK) {
              fprintf(stderr, "%s\n", curl_easy_strerror(res));
          }
          curl_easy_cleanup(curl);
      }
      return (int)res;
  }
  </code></pre>