2 | (_) |__ ___ _ _ _ __| |
3 | | | '_ \ / __| | | | '__| |
4 | | | |_) | (__| |_| | | | |
5 |_|_|_.__/ \___|\__,_|_| |_|
8 How To Use Libcurl In Your Program:
9 (by Ralph Beckmann <rabe@uni-paderborn.de>)
11 NOTE: If you plan to use libcurl.a in Threads under Linux, do not use the old
12 gcc-2.7.x because the function 'gethostbyname' seems not to be thread-safe,
13 that is to say an unavoidable SEGMENTATION FAULT might occur.
24 2. char *url="http://www.domain.com";
25 curl_urlget (URGTAG_URL, url,
26 URGTAG_FLAGS, CONF_NOPROGRESS,
27 URGTAG_ERRORBUFFER, errorBuffer,
28 URGTAG_WRITEFUNCTION, (size_t (*)(void *, int, int, FILE
30 URGTAG_TIMEOUT, 30, /* or anything You want */
34 3. size_t handle_data (const void *ptr, size_t size, size_t nitems,
37 (void)stream; /* stop complaining using g++ -Wall */
38 if ((int)nitems <= 0) {
41 fprintf(stdout, (char *)ptr); /* or do anything else with it */
45 4. Compile Your Program with -I$(CURL_DIR)/include
47 5. Link Your Program together with $(CURL_DIR)/lib/libcurl.a
49 Small Example of How To Use libcurl
51 ----------------------------------------------------------------------
52 /* Full example that uses libcurl.a to fetch web pages. */
54 /* - Test-Program by Ralph Beckmann for using curl in POSIX-Threads */
55 /* Change *url1 and *url2 to textual long and slow non-FRAMESET websites! */
57 1. Compile with gcc or g++ as $(CC):
58 $(CC) -c -Wall -pedantic curlthreads.c -I$(CURL_DIR)/include
62 $(CC) -o curlthreads curlthreads.o $(CURL_DIR)/lib/libcurl.a -lpthread
65 $(CC) -o curlthreads curlthreads.o $(CURL_DIR)/lib/libcurl.a -lpthread
79 size_t storedata (const void *ptr, size_t size, size_t nitems, FILE *stream) {
80 (void)ptr; (void)stream; /* just to stop g++ -Wall complaining */
81 fprintf(stdout, "Thread #%i reads %i Bytes.\n",
82 (int)pthread_self(), (int)(nitems*size));
86 void *urlfetcher(void *url) {
87 curl_urlget (URGTAG_URL, url,
88 URGTAG_FLAGS, CONF_NOPROGRESS | CONF_FAILONERROR,
89 URGTAG_WRITEFUNCTION, (size_t (*)(void *, int, int, FILE
96 char *url1="www.sun.com";
97 char *url2="www.microsoft.com";
99 pthread_t thread_id1, thread_id2;
100 pthread_create(&thread_id1, NULL, urlfetcher, (void *)url1);
101 pthread_create(&thread_id2, NULL, urlfetcher, (void *)url2);
102 pthread_join(thread_id1, NULL);
103 pthread_join(thread_id2, NULL);
105 fprintf(stdout, "Ready.\n");