#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/time.h>
#include <unistd.h>

#include <curl/curl.h>

size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
        int realsize = size * nmemb;
        return realsize;
}


int main(int argc, char **argv)
{
	CURL *http_handles[500];
	CURLM *multi_handle;
	CURLMsg *msg; /* for picking up messages with the transfer status */
	int msgs_left; /* how many messages are left */

	int still_running; /* keep number of running handles */
	int timeout=0,i;

	char *urls[] = {
"http://www.final4ever.com/vb/full-movies/476546-tsubomi-sticky-thick-sex-oned427.html",
"http://www.asianforumer.com/censored-jav-download-links/198326-tsubomi-sticky-thick-sex-oned427.html",
"http://jetdl.com/download/+Bz+Miad+461+Tsubomi+P+Bullying+/3yww4",
"http://x-cornerz.com/2010/11/tsubomi-get-losing-ones-virginity-man-2-ekdv-133/",
"http://forum.isengaje.com/showthread.php?p=511021",
"http://warezhaven.org/porn-adult/adult-video-clips/1053470-asian-movie-star-jav9-update-dialy-6.html",
"http://www.javmoviez.com/2010_07_01_archive.html",
"http://www.intporn.com/forums/asian-jav-movies/1132315-asian-movie-star-jav9-update-dialy-41.html",
"http://www.pornbb.org/post9371487.html",
"http://blog.jav4you.com/2010/08/kaz-052-misaki-sakura-ero-idol-fellatio/",
"http://blog.jav4you.com/2010/11/xv-894-yukino-hotaru-luscious-kissing-and-fucking/",
"http://adult-movdl.blogspot.com/2010/09/annd-066-tsubomi-rui-saotome-lesbian.html",
"http://popularhub.com/rin-sakuragi-lewd-lips-adz082",
"http://goianh.com/index.php?/archives/438-C0930-Lewd-Wives-Wakana-Matsushita.html",
"http://goianh.com/index.php?/archives/2456-Pavillon-Yua-Hagiwara.html",
"http://goianh.com/index.php?/archives/2313-Mondo64-no122-Megu-Japanese-BDSM.html",
"http://forun.8cyber.com/archiver/tid-14735921-page-5.html",
"http://www.dadesiforum.com/index.php?/topic/24760887-asian-movie-star-jav9-update-dialy/page__st__525",
"http://www.dadesiforum.com/Gokkun-and-Bukkake-Movies-collection-t24681069.html&mode=threaded&pid=2450632&tst=400",
"http://gallows-jav.blogspot.com/2010/11/xv883-rin-fujisawa-set-loose-right-from.html",
"http://www.zehrax.com/onanie-paranoia-ddk025",
"http://laksasa.net/2010/07/20/fouls-on-a-beautiful-referee-yui-hatano-071510-427/",
"http://laksasa.net/tag/%%E6%%B3%%A2%%E5%%A4%%9A%%E9%%87%%8E%%E7%%B5%%90%%E8%%A1%%A3/",
"http://laksasa.net/2010/07/20/kamikaze-street-vol-8-arisa-kumada-kst-008/",
"http://www.avcollectors.com/board/index.php?topic=12700.4270",
"http://www.avun.com/Mediafire.com/one-piece-avi-364.html",
"http://funkycavemen.com/forums/showthread.php?tid=18424&page=34"
};



	timeout=3;

	multi_handle = curl_multi_init();


	for(i=0;i<27;i++)
	{
printf("url=%s\n", urls[i]);
		http_handles[i] = curl_easy_init();
		if( !http_handles[i] )
		{
		        fprintf( stderr, "curl_easy_init failed\n" );
		        continue;
		}
		

		curl_easy_setopt(http_handles[i], CURLOPT_URL, urls[i]);
		curl_easy_setopt(http_handles[i], CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
		curl_easy_setopt(http_handles[i], CURLOPT_WRITEDATA, NULL ); // NULL is ok
		curl_easy_setopt(http_handles[i], CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.11" );
		curl_easy_setopt(http_handles[i], CURLOPT_ENCODING, "gzip,deflate");

		curl_easy_setopt(http_handles[i], CURLOPT_TIMEOUT, timeout );
		curl_easy_setopt(http_handles[i], CURLOPT_NOSIGNAL, 1 ); // disable signal timout! not corrected bug ...

		curl_easy_setopt(http_handles[i], CURLOPT_CONNECTTIMEOUT, timeout ); // seconds

		/* add the individual transfers */
		curl_multi_add_handle(multi_handle, http_handles[i]);
	}

	/* we start some action by calling perform right away */
	curl_multi_perform(multi_handle, &still_running);

	while(still_running) {
		struct timeval timeout_tv;
		int rc; /* select() return code */

		fd_set fdread;
		fd_set fdwrite;
		fd_set fdexcep;
		int maxfd = -1;
		
		long curl_timeo = -1;

		FD_ZERO(&fdread);
		FD_ZERO(&fdwrite);
		FD_ZERO(&fdexcep);

		/* set a suitable timeout to play around with */
		timeout_tv.tv_sec = 1;
		timeout_tv.tv_usec = 0;

                curl_multi_timeout(multi_handle, &curl_timeo);
                if(curl_timeo >= 0)
                {
                        timeout_tv.tv_sec = curl_timeo / 1000;
                        if(timeout_tv.tv_sec > 1) timeout_tv.tv_sec = 1;
                        else timeout_tv.tv_usec = (curl_timeo % 1000) * 1000;
                }

		/* get file descriptors from the transfers */
		curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
		
		if( maxfd < -1 )
		{
		        fprintf( stderr, "maxfd=%i\n", maxfd );
		        break;
                }

                rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout_tv);

		switch(rc) {
        		case -1:
        			/* select error */
        			break;
        		case 0: /* timeout */
        		default:
        		        /* readable/writable sockets */
        		        curl_multi_perform(multi_handle, &still_running);
                                break;
		}
printf("still_running=%i\n", still_running );
	}

	printf("Done, bug missed..\n");

	return 0;
}

