-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_cli.c
55 lines (46 loc) · 1.16 KB
/
client_cli.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
#include "cli.h"
#include <stdio.h>
#include <argp.h>
#include <stdlib.h>
static struct {
char *verb;
char *url;
} _settings = {
"GET",
};
static char _doc[] = "HTTP stress test using Linux epoll.";
static char _args_doc[] = "URL [VERB]";
/* Options definition */
static struct argp_option _options[] = {
ARG_VERBOSITY,
ARG_CONCURRENCY,
{ 0 }
};
/* Parse a single option. */
static int
_parse_opt(int key, char *arg, struct argp_state *state) {
switch (key) {
case ARGP_KEY_ARG:
if (state->arg_num == 0) {
_settings.url = arg;
}
else if (state->arg_num == 1) {
_settings.verb = arg;
}
else if (state->arg_num >= 2) {
/* Too many arguments. */
return ARGP_ERR_UNKNOWN;
}
break;
default:
return parse_common_opts(key, arg, state);
}
return EXIT_SUCCESS;
}
static struct argp _argp = { _options, _parse_opt, _args_doc, _doc };
int
clientcli_run(int argc, char **argv) {
argp_parse(&_argp, argc, argv, 0, 0, NULL);
/* Do the job */
return EXIT_SUCCESS;
}