cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: what is the best way to preform http post request every N seconds endlessly

From: Meir Yanovich <meiry242_at_gmail.com>
Date: Wed, 2 Apr 2008 20:18:39 +0200

let me add the simple code :
this is the pthread call :
bool PostRequest::CreateThread(){

        #ifdef PTW32_STATIC_LIB
                pthread_win32_process_attach_np();
        #endif
        
        static struct postRequest_args thread_data_array[NUM_THREADS];
        thread_data_array[0].hostname ="d";
        
        pthread_t threads[NUM_THREADS];
        int rc;
        

        printf("HttpPostHandler::PostRequestInit(): creating thread %d\n", 1);
        
        rc = pthread_create(&threads[0], NULL,PostRequest1,(void *)
&thread_data_array[0]);
    if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
    }

        #ifdef PTW32_STATIC_LIB
                pthread_win32_process_detach_np();
        #endif

        return 1;
}

and this is the cUrl code (inside PostRequest1 function )
void *PostRequest1(void *threadarg){
        
  postRequest_args *t_args = (postRequest_args *) threadarg;
        
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/test");
    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "u=1&p=2");

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }

  int reqReturn = 1;
  return (void *)reqReturn;
}

On Wed, Apr 2, 2008 at 7:54 PM, Meir Yanovich <meiry242_at_gmail.com> wrote:
> yes pthreads win32
> http://sourceware.org/pthreads-win32/
>
> the problem is simple :
> in creating thread that takes function pointer , in this function
> there is the cUrl code ( simple http post )
> what more info do you need ?
>
>
>
> On Wed, Apr 2, 2008 at 4:30 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> > On Wed, 2 Apr 2008, Meir Yanovich wrote:
> >
> >
> > > im working with pthreads and the http request is invoked in separate
> > > thread the problem is
> > >
> >
> > pthreads on windows? If you're doing SSL, did you add the mutex callbacks?
> >
> >
> >
> > > KERNEL32! 7c4fb252()
> > > _CrtIsValidHeapPointer(const void * 0x00992dc0) line 1606
> > > _free_dbg_lk(void * 0x00992dc0, int 1) line 1011 + 9 bytes
> > > _free_dbg(void * 0x00992dc0, int 1) line 970 + 13 bytes
> > > free(void * 0x00992dc0) line 926 + 11 bytes
> > > destroy_thread_sync_data(thread_sync_data * 0x00b9ff70) line 183 + 15
> > bytes
> > > gethostbyname_thread(void * 0x00881140) line 321 + 9 bytes
> > > _threadstartex(void * 0x00882cd0) line 212 + 13 bytes
> > > KERNEL32! 7c4e987c()
> > >
> > > some one knows what is all about ?
> > >
> >
> > Can you repeat the problem?
> >
> > --
> >
> > Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
> >
>
Received on 2008-04-02