int main( int argc, char ** argv ) { mpz_t n, d, e; char * out; int t, r, bits; TS_VAR ts; if ( argc != 2 ) { usage: printf( "usage: g bits, where 32<=bits<=2048\n" ); return 1; } bits = atoi( argv[1] ); if ( bits < 32 || bits > 2048 ) goto usage; mpz_init( n ); mpz_init( d ); mpz_init( e ); TS_START(ts); r = makersa( n, d, e, bits ); t = TS_END(ts); printf( "makersa time = %d ms\n", t ); printf( "reps = %d\n", r ); if ( putkeys( n, d, e, (bits*2/8)-1 ) < 0 ) printf( "error writing keys to disk: %s\n", strerror(errno) ); mpz_clear( n ); mpz_clear( d ); mpz_clear( e ); return 0; }
int main(int argc, char **argv) { memset(&global_info, 0, sizeof(global_info_t)); char *url = http_url; global_info.round = 1; int opt; while ((opt = getopt(argc, argv, "w:t:r:hs")) != -1) { switch (opt) { case 'w': global_info.work_num = atoi(optarg); break; case 't': global_info.thread_num = atoi(optarg); break; case 'r': global_info.round = atoi(optarg); break; case 's': url = https_url; break; case 'h': default: show_help(); return EXIT_SUCCESS; } } if (global_info.work_num == 0 || global_info.thread_num == 0) { show_help(); return EXIT_FAILURE; } setsignal(SIGINT, _sig_int); setsignal(SIGTERM, _sig_int); printf("get work num: %u, thread num: %u\n", global_info.work_num, global_info.thread_num); thread_info_t *thread_list = calloc(global_info.thread_num, sizeof(thread_info_t)); if (thread_list == NULL) { printf("alloc threads error\n"); return EXIT_FAILURE; } global_info.work_list = calloc(global_info.work_num, sizeof(work_info_t *)); if (global_info.work_list == NULL) { printf("alloc work_list error\n"); return EXIT_FAILURE; } int idx = 0; for (idx = 0; idx < global_info.work_num; ++idx) { global_info.work_list[idx] = calloc(1, sizeof(work_info_t)); if (global_info.work_list[idx] == NULL) { printf("alloc work_list %u error\n", idx); return EXIT_FAILURE; } global_info.work_list[idx]->url = url; global_info.work_list[idx]->idx = idx; } /* Must initialize libcurl before any threads are started */ curl_global_init(CURL_GLOBAL_ALL); init_locks(); TS_INIT(); mutexlock_init(global_info.rmtx); mutexlock_init(global_info.wmtx); TS_DECLARE(perf); for (idx = 0; idx < global_info.thread_num; ++idx) { thread_list[idx].global_info = &global_info; thread_list[idx].curl = curl_easy_init(); thread_list[idx].multi_handle = curl_multi_init(); if (thread_list[idx].curl == NULL || thread_list[idx].multi_handle == NULL) { printf("error when curl init\n"); return EXIT_FAILURE; } //curl_easy_setopt(thread_list[idx].curl, CURLOPT_FORBID_REUSE, 1L); curl_easy_setopt(thread_list[idx].curl, CURLOPT_NOSIGNAL, 1L); if (url == https_url) { curl_easy_setopt(thread_list[idx].curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(thread_list[idx].curl, CURLOPT_SSL_VERIFYHOST, 0L); } thread_list[idx].idx = idx; set_share_handle(thread_list[idx].curl); } int error; TS_BEGIN(perf); for (idx = 0; idx < global_info.thread_num; ++idx) { error = pthread_create(&(thread_list[idx].tid), NULL, /* default attributes please */ pull_one_url, (void *) & (thread_list[idx])); if (0 != error) { fprintf(stderr, "Couldn't run thread number %d, errno %d\n", idx, error); return EXIT_FAILURE; } } /* now wait for all threads to terminate */ for (idx = 0; idx < global_info.thread_num; idx++) { error = pthread_join(thread_list[idx].tid, NULL); //printf("[%u:%lu]Thread %d terminated\n", idx, time(NULL), idx); } TS_END(perf); for (idx = 0; idx < global_info.thread_num; idx++) { curl_easy_cleanup(thread_list[idx].curl); curl_multi_cleanup(thread_list[idx].multi_handle); } free(thread_list); unsigned long total_length = 0; for (idx = 0; idx < global_info.work_num; idx++) { if (global_info.work_list[idx]) { if (global_info.work_list[idx]->status == STAT_DONE) { total_length += global_info.work_list[idx]->data_len; } free(global_info.work_list[idx]); } } free(global_info.work_list); printf("RATE: worknum:%u total_length:%lu total_ms_diff:%lu, %.1fK\n", global_info.work_num, total_length, TS_MSDIFF(perf), (double)(total_length) / (double)(TS_MSDIFF(perf))); kill_locks(); curl_global_cleanup(); return EXIT_SUCCESS; }