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: Fri, 4 Apr 2008 17:49:46 +0200

ok first of all can some one change the thread topic to relevat one like :
cUrl and pthread in win32 not working ... or somthing
allso can someone please make the example in cUrl the "multithread.c"
to work on win32
beacose as it is now it is not working .

my linker options are compiling the "multithread.c" as example see the
code adding pthread :
ifdef to work in win32 env :
linker :
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib odbccp32.lib ws2_32.lib libcurld.lib pthreadVC2d.lib
winmm.lib /nologo /subsystem:console /incremental:yes
/pdb:"Debug/cUrl_test3.pdb" /debug /machine:I386
/out:"Debug/cUrl_test3.exe" /pdbtype:sept
/libpath:"..\..\Extlib\curl\lib\Debug"
/libpath:"..\..\\Extlib\pthreads\lib\Debug"

compiler :
/nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\Extlib\pthreads\include" /I
"..\..\Extlib\libwebserver\include" /I "..\..\Extlib\curl\include" /D
"WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "PTW32_STATIC_LIB" /D
"CURL_STATICLIB" /Fp"Debug/cUrl_test3.pch" /YX /Fo"Debug/" /Fd"Debug/"
/FD /GZ /c

the code changed for win32

#include <stdio.h>
#include <pthread.h>
#include <curl/curl.h>

/*
  List of URLs to fetch.

  If you intend to use a SSL-based protocol here you MUST setup the OpenSSL
  callback functions as described here:

  http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION

*/
const char *urls[]= {
  "http://curl.haxx.se/",
  "ftp://cool.haxx.se/",
  "http://www.contactor.se/",
  "www.haxx.se"
};

void *pull_one_url(void *url)
{
  CURL *curl;

  curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_perform(curl); /* ignores error */
  curl_easy_cleanup(curl);

  return NULL;
}

/*
   int pthread_create(pthread_t *new_thread_ID,
   const pthread_attr_t *attr,
   void * (*start_func)(void *), void *arg);
*/

int main(int argc, char **argv)
{

  #ifdef PTW32_STATIC_LIB
                pthread_win32_process_attach_np();
        #endif
  curl_global_init(CURL_GLOBAL_DEFAULT);
  pthread_t tid[4];
  int i;
  int error;
  for(i=0; i< 4; i++) {
    error = pthread_create(&tid[i],
                           NULL, /* default attributes please */
                           pull_one_url,
                           (void *)urls[i]);
    if(0 != error)
      fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
    else
      fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
  }

  /* now wait for all threads to terminate */
  for(i=0; i< 4; i++) {
    error = pthread_join(tid[i], NULL);
    fprintf(stderr, "Thread %d terminated\n", i);
  }
        #ifdef PTW32_STATIC_LIB
                pthread_win32_process_detach_np();
        #endif
  return 0;
}:

thanks for the help

On Fri, Apr 4, 2008 at 7:05 AM, Dan Fandrich <dan_at_coneharvesters.com> wrote:
> On Fri, Apr 04, 2008 at 05:38:43AM +0200, Meir Yanovich wrote:
> > well im using pthread and cUrl in my app only .
>
> You're also using a standard C library whether you know it or not.
>
>
> > also as i said if i make the examples work like the "multithread.c" in
> > curl example dir
> > i hope to learn how to work with cUrl in MT
>
> If you post the linker options you're using, then someone with Win32
> experience could tell you whether they're suitable for a multithreaded app.
>
>
>
> >>> Dan
> --
> http://www.MoveAnnouncer.com The web change of address service
> Let webmasters know that your web site has moved
>
Received on 2008-04-04