forked from hzzlzz/crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
58 lines (48 loc) · 1.23 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "crawler_core.h"
/*
void set_nonblocking(int sockfd)
{
int opts;
opts = fcntl(sockfd, F_GETFL);
if (opts < 0 )
handle_error("fcntl");
opts = opts | O_NONBLOCK;
if (fcntl(sockfd, F_SETFL, opts) < 0 )
handle_error("fcntl");
}
*/
/* Program starts here */
int main(int argc, char *argv[]) {
int opt, num_threads, max_waiting, max_total;
char *seed;
num_threads = 0;
max_waiting = 0;
max_total = 0;
seed = NULL;
while((opt = getopt(argc, argv, "t:w:v:")) != -1) {
switch(opt) {
case 't':
num_threads = strtoul(optarg, NULL, 0);
break;
case 'w':
max_waiting = strtoul(optarg, NULL, 0);
break;
case 'v':
max_total = strtoul(optarg, NULL, 0);
break;
default:
fprintf(stderr, "Usage: %s -t num-threads -w waiting-list-size -v max-visit-num init-url(without http://)", argv[0]);
exit(EXIT_FAILURE);
}
}
seed = argv[optind];
if(num_threads == 0 || max_waiting == 0 || max_total == 0 || seed == NULL) {
fprintf(stderr, "Usage: %s -t num-threads -w waiting-list-size -v max-visit-num init-url(without http://)\a\n", argv[0]);
exit(EXIT_FAILURE);
}
start(seed, max_waiting, max_total, num_threads);
exit(EXIT_SUCCESS);
}